ThinkPHP 百度编辑器富文本过滤XSS攻击实例操作!
准备:1,下载Htmlpurifier 2,在公共函数写一个方法!
一、下载:Htmlpurifier,下载的网址是:http://htmlpurifier.org/
放在根目录就行了
二、在 function.php 方法中
function removeXSS($data)
{
require_once './HtmlPurifier/HTMLPurifier.auto.php';
$_clean_xss_config = HTMLPurifier_Config::createDefault();
$_clean_xss_config->set('Core.Encoding', 'UTF-8');
// 保留的标签
$_clean_xss_config->set('HTML.Allowed', 'div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]');
$_clean_xss_config->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
$_clean_xss_config->set('HTML.TargetBlank', TRUE);
$_clean_xss_obj = new HTMLPurifier($_clean_xss_config);
return $_clean_xss_obj->purify($data);
}
三、直接使用
例如:
这样子就可以在富文本中过滤脚本的代码了!