Several methods to prevent injection in php _ PHP Tutorial

Source: Internet
Author: User
Php prevents injection. Several methods to prevent injection in the php Tutorial are actually we need to filter some of our common keywords and conformances, such as select, insert, update, delete, and *. for example: several methods to prevent injection in the php Tutorial

In fact, it turns out that we need to filter out some common keywords and conformances such:

Select, insert, update, delete, and, *, etc.

Example:

Function inject_check ($ SQL _str ){
Return eregi ('select | insert | update | delete | '|/* |.../|./| union | into | load_file
| Outfile ', $ SQL _str); // filter
}

Or filter Special characters between system functions.

Addslashes (content to be filtered)

2. php security settings in other places

1. set register_globals = off to disabled.

2. do not omit small quotation marks or single quotation marks when writing SQL statements.

Select * from table where id = 2 (not standard)

Select * from · table · where · id · = '2' (standard)

3. use accepted parameters such as $ _ post $ _ get $ _ session correctly and filter them.

4. Improve the naming skills of database tutorials. you can name important fields according to program characteristics.

5. encapsulate common methods to avoid direct exposure of SQL statements

There are several ways to prevent injection by using the distinct statement. In fact, we need to filter some common keywords and conformances such as select, insert, update, delete, and *. for 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.