Php filters dangerous code submitted by forms (prevents php injection ). 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, if the security of each form submission is poor, it is easy to attack the website because of this form submission. I will share two examples of dangerous code commonly used php filtering form submission, for more information, see.
Example 1
| 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
Can joinFilter
"/<(/?) (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: |
|
|
// 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]: '');
}
}
} |
...