Classic PHP anti-injection function code_PHP tutorial

WBOY
Release: 2016-07-13 17:09:31
Original
1602 people have browsed it

/*************************
Description:
Determine whether the passed variable contains illegal characters
Such as $_post, $_get
Function:
Anti-injection
**************************/
//Illegal characters to be filtered This filtered character can also be added
$arrfiltrate=array("'",";","union");
//The URL to jump to after an error occurs. If not filled in, the previous page will be defaulted
$strgourl="";
//Whether there is a value in the array
function funstringexist($strfiltrate,$arrfiltrate){
foreach ($arrfiltrate as $key=>$value){
if (eregi($value,$strfiltrate)){
return true;
}
}
return false;
}

//Merge $_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;
}
}

//Verification starts
foreach($arrpostandget as $key=>$value){
if (funstringexist($value,$arrfiltrate)){
echo "";
if (empty($strgourl)){
echo "";
}else{
echo "";
}
exit;
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629728.htmlTechArticle?php tutorial/************************* Description: Determine whether the passed variables contain illegal characters such as $_post, $_get Function: Anti-injection****** ********************/ //Illegal to filter...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template