Htmlpurifier Filter the Dangerous JS code

Source: Internet
Author: User

Inside the public function functions

Selective filtering XSS-"Description: Very low performance-" Try to use less
function Removexss ($data)
{
Require_once './htmlpurifier/htmlpurifier.auto.php ';
$_clean_xss_config = Htmlpurifier_config::createdefault ();
$_clean_xss_config->set (' core.encoding ', ' UTF-8 ');
Set a reserved label
$_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);
Perform filtering
Return $_clean_xss_obj->purify ($data);
}

Call this method in the model

protected function _before_insert (& $data, $option)
{
Gets the current time added to the form
$data [' Addtime ']=date (' y-m-d h:i:s ', Time ());

We'll filter this field by ourselves.
$data [' Goods_desc ']= removexss ($_post[' Goods_desc ']);
}

If you use an online editor in your project, you need to use Htmlpurifer to implement selective filtering XSS!!

Htmlpurifier Filter the Dangerous JS code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.