Filter dangerous html code in form submission using php

Source: Internet
Author: User
Html code that uses PHP to filter submitted forms may contain code that introduces external dangerous content. For example, when a user submits a form that contains html content, the layout of the displayed page may be messy, the html code that needs to be filtered out using PHP to filter the submitted form may be exploited to introduce external dangerous content. For example, some forms submitted by the user contain html content, but this may cause confusion in the layout of the display page and need to be filtered out.
The following is the program code:
Function uhtml ($ str)
{
$ Farr = array (
"// \ S +/", // filter unnecessary spaces
// Filter scripts and other code that may introduce malicious content or maliciously change the display layout. if you do not need to insert flash, you can also addFilter
"/<(\/?) (Script | I? Frame | style | html | body | title | link | meta | \? | \ %) ([^>] *?)> /IsU ",
"/(<[^>] *) On [a-zA-Z] + \ s * = ([^>] *>)/isU ", // filter javascript on events
);
$ Tarr = array (
"",
"<\ 1 \ 2 \ 3>", // If you want to directly clear insecure labels, leave it blank.
"\ 1 \ 2 ",
);
$ Str = preg_replace ($ farr, $ tarr, $ str );
Return $ str;
}

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.