Brief description: /*************************
Description:
Determine whether the passed variable contains illegal characters
Such as $_POST, $_GET
Function: Anti-injection
* *************************/
Copy code The code is as follows:
//Illegal characters to be filtered
$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($ArrPostAndGet as $key=>$value ){
if (FunStringExist($value,$ArrFiltrate)){
echo ""; if (emptyempty($StrGoUrl ; location="".$StrGoUrl."";";
Then add include( before each php file "checkpostandget.php"); then
Method 2
Copy the code
The code is as follows:
G/*Filter all Get variables*/
Foreach ($_Get as $ get_key = & gt; $ get_var) {
(inumeric ($ get_var)) {
$ get [StrTolower ($ GET_KEY)]] et_int ( $get_var);
} else {
$get[strtolower($get_key)] = get_str($get_var);
}
/* Filter all POST variables */
foreach ($_POST as $post_key=> ;$post_var)
{
if (is_numeric($post_var)) {
$post[strtolower($post_key)] = get_int($post_var);
} else {
$post[strtolower($post_key) ] = get_str( $post_var);
}
}
/* Filter function */
//Integer filter function
function get_int($number)
{
return intval($number);
}
//String filter function
function get_str($string)
The above introduces the photoshop cs5 official Chinese official original download PHP anti-injection security code, including the photoshop cs5 official Chinese official original download content. I hope it will be helpful to friends who are interested in PHP tutorials.