SQL general anti-injection system _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.