Programs may cause normal use of other programs and are trying to improve them!
Comments and corrections
<? Php
/* PHP universal injection prevention cross-site V1.1
################## Contact address ##################
Http://hi.baidu.com/menzhi007
################## Instructions ##################
Add require ("SQL _injection.php") at the top of your page ");
To prevent SQL injection and cross-site XSS vulnerabilities.
################## Defects and improvements ##################
There are still many defects in the program. I hope you can help improve it.
################## Reference and appreciation ##################
NeeaoASP SQL universal anti-injection program V3.0
Some code can be found in Discuz!
*/
Error_reporting (0 );
Define (MAGIC_QUOTES_GPC, get_magic_quotes_gpc ());
If (PHP_VERSION <4.1.0 ){
$ _ GET = & $ HTTP_GET_VARS;
$ _ POST = & $ HTTP_POST_VARS;
$ _ COOKIE = & $ HTTP_COOKIE_VARS;
$ _ SERVER = & $ HTTP_SERVER_VARS;
$ _ ENV = & $ HTTP_ENV_VARS;
$ _ FILES = & $ HTTP_POST_FILES;
}
Foreach (array (_ GET, _ POST, _ COOKIE, _ REQUEST) as $ _ request ){
Foreach ($ _ request as $ _ key => $ _ value ){
$ SQL _injection = "|; | and | (|) | exec | insert | select | delete | update | count | % | chr | mid | master | truncate | or | char | declare | benchmark | script | javascript | <|> ";
$ SQL _injection = explode ("|", $ SQL _injection );
Preg_match ("/[^ 0-9] */", $ _ key )? $ _ Key: $ _ key =;
Daddslashes ($ _ key );
Daddslashes ($ _ value );
$ _ Value = strtolower ($ _ value );
Foreach ($ SQL _injection as $ kill_key => $ kill_value ){
If (substr_count ($ _ value, $ kill_value)> 0 ){
Echo "<script> alert (Error, Do not enter illegal characters:". $ kill_value ."! Please Content menzhi007@163.com !); History. back (); </script> ";
Unset ($ _ request, $ _ key, $ _ value );
Exit ();
}
}
}
}
Function daddslashes ($ string ){
If (! MAGIC_QUOTES_GPC ){
If (is_array ($ string )){
Foreach ($ string as $ key => $ val ){
$ String [$ key] = daddslashes ($ val );
}
} Else {
$ String = addslashes ($ string );
}
}
$ String = preg_replace (/& (# (d {3, 5} | x [a-fA-F0-9] {4});)/, & \ 1, str_replace (array (&, ", <,>), array (&,", <,>), $ string ));
Return $ string;
}
?>