【问题标题】:MY SQL Query for remove all a tags from field用于从字段中删除所有标签的 MY SQL 查询
【发布时间】:2019-04-27 10:16:09
【问题描述】:

我有一个 WordPress 网站,最近受到恶意软件攻击。我设法删除了所有恶意软件文件和广告安全。

但是那个黑客在所有帖子内容的末尾注入了一些如下所示的随机网址。该网站有大约 1500 条帖子。

<a href="http://www.cgparkaoutlet.com">canada goose outlet</a>  <a href="http://www.cgparkaoutlet.com">canada goose outlet</a>

我需要删除这些链接。已经测试过这个 mysql 但它不工作

UPDATE wp_posts SET post_content = REPLACE(post_content, substring_index( substring_index(post_content, 'href="', -1),  '"', 1),'');
UPDATE wp_posts SET post_content = REPLACE(post_content, '<a href="">','');
UPDATE wp_posts SET post_content= REPLACE(post_content, '<a href="" target="_blank">','');
UPDATE wp_posts SET post_content= REPLACE(post_content, '</a>','');

任何人都知道如何在不老化内容的情况下从所有帖子中删除这些链接。谢谢你

【问题讨论】:

  • 您可以对发布的内容进行htmlentities()。所以,JS 不会执行。
  • 你的post_content列中不会有其他非恶意的&lt;a href=......&lt;/a&gt;
  • 检查这个答案:stackoverflow.com/a/53286571/2469308你可能会从中得到一些想法。
  • 不要用mysql做解析/替换。这是非常有限的。在 PHP 中从数据库中选择数据,对其运行函数以删除恶意数据,然后更新记录。
  • 是的,有像 这样的非恶意 a 标签,我也想保留这些标签,唯一的好处是这些注入的链接是在内容的末尾

标签: php mysql wordpress


【解决方案1】:

我建议你,例如使用 wp_strip_all_tags wordpress 功能:

global $wpdb;
$wpdb->query("update `wp_posts` set post_content = ".wp_strip_all_tags( $string ) ....);

https://codex.wordpress.org/Function_Reference/wp_strip_all_tags

【讨论】:

  • 实际上我无法剥离所有标签,因为也有图像标签,也有图像标签被标签扭曲,这些标签也需要保留,这似乎有点困难
  • 这个函数有两个$remove_breaks参数请看文档..w3schools.com/php/func_string_strip_tags.asp
猜你喜欢
  • 2017-04-20
  • 1970-01-01
  • 2019-06-21
  • 2020-02-14
  • 2019-10-14
  • 2022-01-22
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
相关资源
最近更新 更多