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. PHP filters the html code of the submitted form, which 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.
Method 1:
The Code is as follows:
// 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]: '');
}
}
}
Method 2:
The Code is as follows:
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;
}
This is a practical method. I hope it will be helpful to you.