Classic PHP anti-injection function code _php tutorial

Source: Internet
Author: User

/*************************
Description
Determine if the passed variable contains illegal characters
such as $_post, $_get
Function:
Anti-injection
**************************/
To filter the illegal characters, this filtered character can also be added
$arrfiltrate =array ("'", ";", "union");
The URL to jump after the error, without filling the default previous page
$strgourl = "";
Whether the values in the array exist
function Funstringexist ($strfiltrate, $arrfiltrate) {
foreach ($arrfiltrate as $key = = $value) {
if (eregi ($value, $strfiltrate)) {
return true;
}
}
return false;
}

Merging $_post and $_get
if (function_exists (Array_merge)) {
$arrpostandget =array_merge ($http _post_vars, $http _get_vars);
}else{
foreach ($http _post_vars as $key = + $value) {
$arrpostandget []= $value;
}
foreach ($http _get_vars as $key = + $value) {
$arrpostandget []= $value;
}
}

Validation begins
foreach ($arrpostandget as $key = = $value) {
if (Funstringexist ($value, $arrfiltrate)) {
echo "";
if (empty ($strgourl)) {
echo "";
}else{
echo "";
}
Exit
}
}
?>

http://www.bkjia.com/PHPjc/629728.html www.bkjia.com true http://www.bkjia.com/PHPjc/629728.html techarticle PHP Tutorial/************************* Description: Determine whether the passed variable contains illegal characters such as $_post, $_get function: Anti-injection **************************///illegal to filter ...

  • 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.