SQL universal anti-injection system. SQL universal anti-injection system this article provides this anti-SQL injection code as a function for phpsql double filter of illegal characters, which can be customized to prevent SQL injection, first, filter some sq SQL general anti-injection systems this article provides this anti-SQL injection code is a php SQL double filter function for illegal characters, based on user-defined anti-SQL injection, it is best to filter some SQL commands, and then filter post get once.
SQL universal anti-injection system
This article provides this anti-SQL injection code, which is a php Tutorial SQL double filter function for illegal characters. it can prevent SQL injection based on user-defined settings. First, it filters some SQL commands, the second is to filter the post get once. it is best to verify it.
*/
// Anti-injection
$ Arrfiltrate = array ("update", "delete", "selert", "drop", "exec", "cast", "'", "union ");
// The url to be redirected after an error occurs. If this parameter is left blank, the previous page is displayed by default.
$ Strgourl = "";
// Whether the value in the array exists
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 "";
}
Echo "script" alert ('The system has detected illegal characters! '); History. back (); script ";
Exit ();
}
}
?>
SQL double filter function for illegal characters, which can prevent SQL injection based on user-defined, first filter some sq...