PHP filters HTML and other dangerous codes submitted by forms, PHP filters form submissions_PHP tutorial

WBOY
Release: 2016-07-13 10:15:25
Original
902 people have browsed it

php filters html and other dangerous codes submitted by forms, php filters form submissions

The html code of the PHP filter submission form may contain code that can be exploited to introduce external dangerous content. For example, sometimes the user submission form contains HTML content, but this may cause confusion in the display page layout and needs to be filtered out.

Method 1:

Copy code 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:

Copy code The code is as follows:

function uhtml($str)
{ 
$farr = array(
"/s+/", //Filter excess blanks
//Filter
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!