Home  >  Article  >  Backend Development  >  Classic PHP anti-injection function code_PHP tutorial

Classic PHP anti-injection function code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:09:311564browse

/*************************
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...
Statement:
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