Php anti-SQL injection program code _ PHP Tutorial

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

  1. [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 ;}

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.