Dangerous code for php Filter Form submission (php injection Prevention)

Source: Internet
Author: User

If the security of Form submission is poor, it is easy to attack the website because of this form submission. Here I will share two examples of dangerous code commonly used php Filter Form submission, for more information, see.

Example 1

 

The Code is as follows: Copy code

Function uhtml ($ str)
{
$ Farr = array (
"/S +/", // filter unnecessary Spaces
// Filter <script> and other code that may introduce malicious content or maliciously change the display layout. If you do not need to insert flash

You can add <object> filter.
"/<(/?) (Script | I? Frame | style | html | body | title | link | meta |? | %) ([^>] *?)> /IsU ",
"/(<[^>] *) On [a-zA-Z] + s * = ([^>] *>)/isU ", // filter javascript on events
);
$ Tarr = array (
"",
"<123>", // If You Want To directly clear insecure labels, leave it blank.
"12 ",
);
$ Str = preg_replace ($ farr, $ tarr, $ str );
Return $ str;
}

Example 2
Or

The Code is as follows: Copy code

// Get post data
Function PostGet ($ str, $ post = 0)
{
Empty ($ str )? Die ('para is null'. $ str .'! '):'';

If ($ post)
{
If (get_magic_quotes_gpc ())
{
Return htmlspecialchars (isset ($ _ POST [$ str])? $ _ POST

[$ Str]: '');
}
Else
{
Return addslashes (htmlspecialchars (isset ($ _ POST [$ str])?

$ _ POST [$ str]: '');
}

}
Else
{
If (get_magic_quotes_gpc ())
{
Return htmlspecialchars (isset ($ _ GET [$ str])? $ _ GET [$ str]: '');
}
Else
{
Return addslashes (htmlspecialchars (isset ($ _ GET [$ str])?

$ _ GET [$ 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.