htmlpurifier-Rich Text editor filtering XSS

Source: Internet
Author: User

This post language environment: PHP; Development framework: TP3.2;

1, Htmlpurifier-4.6.0:https://files.cnblogs.com/files/samgo/htmlpurifier-4.6.0.zip

Unzip the downloaded package, modify the name to Htmlpurifier, and put it in the following directory:

2. Define public Function Clearxss (), Path: application/common/common/function.php (note function.php cannot be written functions.php)

/*filtering XSS functions*/functionCLEARXSS ($string){    require_once'./htmlpurifier/htmlpurifier.auto.php '; //build Configuration Object    $_clean_xss_config= Htmlpurifier_config::Createdefault (); //Here is the configuration:    $_clean_xss_config->set (' core.encoding ', ' UTF-8 '); //Set HTML tags that are allowed to be used    $_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] '); //to set CSS style properties that are allowed to appear    $_clean_xss_config->set (' CSS. Allowedproperties ', ' Font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color, Background-color,text-align '); //set whether target= "_blank" is allowed on a label    $_clean_xss_config->set (' HTML. Targetblank ',TRUE); //using configuration to generate filtered objects    $_clean_xss_obj=NewHtmlpurifier ($_clean_xss_config); //Filter Strings    return $_clean_xss_obj->purify ($string);}

3, post submission, in addition to Rich text editor (such as product description) post data (such as product name, price, etc.) with the large I function TP filter, Rich text content with CLEARXSS () function filter;

Note: Rich text and non-rich text content is best filtered separately, if the unified use of CLEARXSS () filtering, non-rich text content submission can be submitted CLEARXSS () allowed to use HTML tags, affecting the page display effect.

htmlpurifier-Rich Text editor filtering XSS

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.