PHP magic_quotes_gpc usage

Source: Internet
Author: User

FromHttp://developer.51cto.com/art/200911/165392.htm

1.
Condition: PhP magic_quotes_gpc = off
The string written to the database has not been filtered. The strings read from the database are not processed.

 

Data: bytes $ DATA = "snow" ''sun "; (four consecutive single quotes between snow and Sun ).

Operation: Write the string: "snow" ''sun "to the database,

Result: if an SQL statement error occurs, MySQL cannot complete the SQL statement successfully and fails to write data to the database.

Database storage format: no data.

Output Data Format: no data.

Note: An SQL statement error occurs when unprocessed single quotes are written to the database.

2.
Condition: PhP magic_quotes_gpc = off
The string written to the database is processed by the addlashes () function. Strings read from the database are not processed.

Data: bytes $ DATA = "snow" ''sun "; (four consecutive single quotes between snow and Sun ).

Operation: Write the string: "snow" ''sun "to the database,

Result: The SQL statement is successfully executed and data is successfully written to the database.

Database storage format: snow "'' Sun (same as input)

Output Data Format: snow "'' Sun (same as input)

Note: The addslashes () function converts single quotation marks to escape characters of \ 'so that the SQL statement is successfully executed,
However, \ 'is not stored in the database as data. The database stores snow "'' sun, not the snow \' \ 'Sun.

3.
Condition: PhP magic_quotes_gpc = on
The string written to the database has not been processed. Strings read from the database are not processed.

Data: bytes $ DATA = "snow" ''sun "; (four consecutive single quotes between snow and Sun ).

Operation: Write the string: "snow" ''sun "to the database,

Result: The SQL statement is successfully executed and data is successfully written to the database.

Database storage format: snow "'' Sun (same as input)

Output Data Format: snow "'' Sun (same as input)

Note: PhP magic_quotes_gpc = on converts single quotes to \ 'escape characters so that the SQL statement is successfully executed,
However, \ 'is not used as data into the database, and the database stores snow "'' sun, rather than snow \' \ 'Sun.

4.
Condition: PhP magic_quotes_gpc = on
The string written to the database is processed by the addlashes () function. Strings read from the database are not processed.

Data: bytes $ DATA = "snow" ''sun "; (four consecutive single quotes between snow and Sun ).

Operation: Write the string: "snow" ''sun "to the database,

Result: The SQL statement is successfully executed and data is successfully written to the database.

Database storage format: snow \ 'Sun (escape characters added)

Output Data Format: snow \ 'Sun (escape characters added)

Note: PhP magic_quotes_gpc = on converts single quotes to \ 'escape characters so that the SQL statement is successfully executed,
Addslashes converts the single quotation marks (\) to be written into the database, and the latter conversion is written as data.
Database. The database stores snow \ '\ 'Sun

Summary:
1. For PHP magic_quotes_gpc = on,

We may not use the string data of the input or output database
The operation of addslashes () and stripslashes () will also display the data normally.

If you perform addslashes () processing on the input data,
In this case, you must use stripslashes () to remove unnecessary backslash.

2. php magic_quotes_gpc = off

You must use addslashes () to process the input data, but you do not need to use stripslashes () to format the output.
Because addslashes () does not write the backslash together into the database, it only helps MySQL to complete SQL statement execution.

Supplement:

PHP magic_quotes_gpc: Web Client Server; Time: When the request starts, for example, when the script is running.
Magic_quotes_runtime: The data read from the file, the result of executing exec (), orResult obtained in SQL query; time: the data generated when the script accesses the running status each time.

 

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.