Several ways to prevent injection in PHP _php tutorial

Source: Internet
Author: User
PHP tutorial several ways to prevent injection

Actually it turns out that we need to filter some of our common keywords and conform to such as:

select,insert,update,delete,and,*, wait.

Example:

function Inject_check ($sql _str) {
Return eregi (' select|insert|update|delete| ' | /*|*|.. /|. /|union|into|load_file
|outfile ', $sql _str); To filter
}

or by filtering special symbols between system functions.

Addslashes (content that needs to be filtered)

Second, PHP other local security settings

1, register_globals = Off set to OFF state

2. Try not to omit Kohiki and single quotes when writing SQL statements

SELECT * FROM table where id=2 (not canonical)

SELECT * FROM Table WHERE id = ' 2 ' (specification)

3, the correct use $_post $_get $_session and other acceptance parameters, and to be filtered

4, improve the database tutorial naming skills, for some important fields can be named according to the program characteristics

5, for common methods to encapsulate, to avoid direct exposure to SQL statements

http://www.bkjia.com/PHPjc/629718.html www.bkjia.com true http://www.bkjia.com/PHPjc/629718.html techarticle PHP Tutorial To prevent the injection of a few ways in fact, we need to filter some of our common keywords and conform to such as: select,insert,update,delete,and,*, and so on example: ...

  • 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.