html实体还是 htmlspecialchars 或 stripslashes?使用哪一个


htmlentities or htmlspecialchars or stripslashes? Which one to use?

当我将用户输入数据插入我使用的 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

使用htmlspecialchars()来防止XSS攻击

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

防止 XSS 攻击

相关文章: