Php filters malicious html characters

Source: Internet
Author: User
Currently, when users submit content at the front-end, they generally use the html editor, which not only enriches the submitted content, but also brings a better user experience, however, the danger is that some users submit malicious html code and other illegal characters, which may cause page confusion.

Currently, when users submit content at the front-end, they generally use the html editor, which not only enriches the submitted content, but also brings a better user experience, however, the danger is that some users submit malicious html code and other illegal characters, which may cause page confusion. you can use the following filter function to relax...

See the following php code:


 ] *?)> /IsU ", // filters malicious code such as scripts. you can also add the object filter flash"/(<[^>] *) on [a-zA-Z] + \ s * = ([^>] *>)/isU ", // filter javascript on events ); $ tarr = array ("", "<\ 1 \ 2 \ 3>", // If you want to directly clear insecure tags, "\ 1 \ 2",); $ str = preg_replace ($ farr, $ tarr, $ str); return $ str ;} // echo filter ("script" alert ('www .phpddt.com '> script ") in a small demo;?>

Running result: <script> alert ('www .phpddt.com '> </script>

Seeing the results, we can easily solve the security crisis...

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.