Php anti-SQL injection program code. This article shares a complete example to describe the php anti-SQL injection code. if you need it, please refer to this article. The code is as follows: Copy the code? ******************* Put it in a public call file (such as a conn Database link file ), filter special strings for all GET or POST data to implement simple and effective SQL injection filtering. PHP beginners. thank you for your criticism. thank you!
[Code] simple functions plus judgment
Function inject_check ($ SQL _str) {return eregi ('select | insert | and | or | update | delete | \ '| \/\ * | \. \. \/| \. \/| union | into | load_file | outfile ', $ SQL _str);} if (inject_check ($ _ SERVER ['query _ string']) = 1 or inject_check (file_get_contents ("php: // input") = 1) {// echo "warns of unauthorized access! "; Header (" Location: Error. php ");}
2. [code] (updated in December 23, 2013) combined with the instructions of everyone, how do you think? Thank you for your continued criticism! (Case insensitive)
Function inject_check ($ SQL _str) {return preg_match ('/select | insert | and | or | update | delete | \' | \/\ * | \. \. \/| \. \/| union | into | load_file | outfile/I ', $ SQL _str);} if (inject_check ($ _ SERVER ['query _ string']) = 1 or inject_check (file_get_contents ("php: // input") = 1) {// echo "warns of unauthorized access! "; Header (" Location: Error. php "); exit ;}