htmlentities或htmlspecialchars或stripslashes?哪一个使用?

时间:2012-06-29 08:59:03

标签: php

当我将用户输入数据插入mysql数据库时,我使用mysql_real_escape_string。输入数据包含bbcode,例如[img][/img]

下面是输出html的行。

    $information = $this->bbcode(stripslashes($this->swearfilter($row['information'])),1);
   echo $information;

关于此示例,这是防止XSS攻击的正确方法还是使用htmlspecialchars($var,ENT_QUOTES)htmlentities

2 个答案:

答案 0 :(得分:2)

使用htmlspecialchars()来阻止XSS攻击

答案 1 :(得分:0)

$message = preg_replace('#\[img\](.*?)\[/img\]#', '<img src="$1" />', $message);  

Prevent XSS Attacks

相关问题