PHP magic_quotes_gpc usage

Source: Internet
Author: User

What we want to introduce to you today is: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 quotes to escape characters so that SQL statements are successfully executed,
However, 'the database does not store data into the database. The database stores snow. ''' sun, not the snow ''' we imagined.

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, 'the database does not store data into the database. The database stores snow. ''' sun, not the snow ''' we imagined.

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 quotes that will be written into the database into ', 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 exec () execution result, or the result obtained from the SQL query. function time: the data generated every time the script accesses the running state.
 


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.