Php filters dangerous Code such as html submitted by Form submission, php filters form submission
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:
Copy codeThe 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:
Copy codeThe Code is as follows:
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 also 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 (
"",
"<\ 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.
Use PHP to filter the HTML and invalid characters of the form.
If you have not enabled the magic function, you can use the function to automatically escape it.
Use the addslashes function to escape the client data. For example:
$ Post = addslashes ($ _ POST ['value']);
At this time, the escape text is displayed!
PHP submits html Forms
Your HTML code is incorrect.
... You do not need to <form> enclose the entire table and then enclose a button. You cannot obtain the value in this way.
Modified HTML code:
<Form method = "post" action = "tijiao. php">
<Table class = "f14" border = "0" cellSpacing = "3" id = "table7">
<Tr>
<Td height = "5"> </td>
</Tr>
<Tr vAlign = "top">
<Td width = "75" align = "right"> <font size = "2"> your message: </font> </td>
& Lt; td width = "325" & gt;
<Textarea style = "WIDTH: 325px; FONT-SIZE: 14px "wrap =" virtual "rows =" 7 "cols =" 45 "name =" liuyan "> </textarea> </td>
</Tr>
<Tr>
<Td height = "5"> </td>
</Tr>
<Tr>
<Td width = "75" align = "right">
<P align = "center"> <font size = "2"> contact information: <br>
QQ or email </font> </p>
<Td width = "325"> <input style = "WIDTH: 325px; FONT-SIZE: 14px" size = "45" name = "email"/> </td>
</Tr>
<Tr>
<Td height = "6"> </td>
</Tr>
<Tr>
<Td> </td>
<Td align = "left">
<Input type = "submit" value = "submit & q ...... remaining full text>