Copy Code code as follows:
? Php
PHP Whole station Anti-injection program, need to require_once the document in the public file
Judge the state of MAGIC_QUOTES_GPC
if (@get_magic_quotes_gpc ()) {
$_get = sec ($_get);
$_post = sec ($_post);
$_cookie = sec ($_cookie);
$_files = sec ($_files);
}
$_server = sec ($_server);
Function sec (& $array) {
If it's an array, iterate through the array, recursively call the
if (Is_array ($array)) {
foreach ($array as $k => $v) {
$array [$k] = sec ($v);
}
else if (is_string ($array)) {
Use the Addslashes function to handle
$array = Addslashes ($array);
else if (Is_numeric ($array)) {
$array = Intval ($array);
}
return $array;
}
Integer Filter function
function Num_check ($id) {
if (! $id) {
Die (' parameter cannot be empty! ' );
}//IS NULL judgment
else if (Inject_check ($id)) {
Die (' illegal parameters ');
}//Injection judgment
else if (! is_numetic ($id)) {
Die (' illegal parameters ');
}
Digital judgment
$id = Intval ($id);
Integral type
return $id;
}
Character Filter function
function Str_check ($STR) {
if (Inject_check ($STR)) {
Die (' illegal parameters ');
}
Injection judgment
$str = Htmlspecialchars ($STR);
Convert HTML
return $str;
}
function Search_check ($STR) {
$str = Str_replace ("_", "\_", $str);
To filter Out "_"
$str = str_replace ("%", "\%", $str);
Filter out "%"
$str = Htmlspecialchars ($STR);
Convert HTML
return $str;
}
Form Filter Functions
function Post_check ($str, $min, $max) {
if (Isset ($min) && strlen ($STR) < $min) {
Die (' least $min byte ');
else if (isset ($max) && strlen ($STR) > $max) {
Die (' Maximum $max bytes ');
}
Return Stripslashes_array ($STR);
}
Anti-injection function
function Inject_check ($sql _str) {
Return eregi (' select|inert|update|delete|\ ' |\/\*|\*|\.\.\/|\.\/| Union|into|load_file|outfile ', $sql _str);
Www.jb51.net for filtration, anti-injection
}
Function Stripslashes_array (& $array) {
if (Is_array ($array)) {
foreach ($array as $k => $v) {
$array [$k] = Stripslashes_array ($v);
}
else if (is_string ($array)) {
$array = Stripslashes ($array);
}
return $array;
}
?>