Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php HTML净化器在插入mysql之前不使用$\u POST_Php_Jquery_Mysql_Wordpress_Htmlpurifier - Fatal编程技术网

Php HTML净化器在插入mysql之前不使用$\u POST

Php HTML净化器在插入mysql之前不使用$\u POST,php,jquery,mysql,wordpress,htmlpurifier,Php,Jquery,Mysql,Wordpress,Htmlpurifier,我在wordpress的博客上有这篇文章,我想在插入数据库之前使用HTML净化器来净化用户的输入。文本编辑器是一个iframe,因此我使用 document.getElementById("comments_comments").value=$("#textEditor").contents().find("body").html(); 当用户单击提交按钮时 我遵循html净化器的基本说明,如下所示: if (isset($_SESSION["user"]) && $

我在wordpress的博客上有这篇文章,我想在插入数据库之前使用
HTML净化器
来净化用户的输入。文本编辑器是一个iframe,因此我使用

   document.getElementById("comments_comments").value=$("#textEditor").contents().find("body").html();
当用户单击提交按钮时

我遵循html净化器的基本说明,如下所示:

  if (isset($_SESSION["user"]) && $_SESSION["user"] != "") 
  {   
    require_once '/path/to/HTMLPurifier.auto.php';

    $config = HTMLPurifier_Config::createDefault();
    $purifier = new HTMLPurifier($config);
    $comments = $purifier->purify($_POST["comments"]);
    $sql = $wpdb->prepare ("INSERT INTO mytable SET comments = %s",array($comments));
    $wpdb->query($sql);
  }

但是代码根本没有任何效果。我希望
标记被完全删除,但它们仍然作为<;脚本>;我认为这是wpdb准备声明的工作。上述配置是否不适用于
$\u POST
?任何帮助都将不胜感激。

首先确保您确实不允许使用此标签:

$config->set('HTML.ForbiddenElements', ['script']));
您正在谈论在数据库中以以下内容结束:

& lt ;script & gt ;
您确定尚未使用
htmlspecialchars()
?也许是这样的

foreach ($_POST as $key => $value) {
    $_POST[$key] = htmlspecialchars($value)
}

我99.99%肯定,这与数据库无关。如果您想执行
var\u dump($comment)
而不是插入到数据库中,那么情况也是一样的。

如果您想简单地清理用户输入,htmlspecialchars()就可以了。如果要删除所有标记(只有在格式从HTML转换为TXT时才适用),striptags()和htmlspecialchars()就可以了。不管怎样,HTML净化器太过分了。@Xabier,我想保留HTML标记。还有其他选择吗?我明白了。。然后,检查这个答案