In-depth explanation of PHPmagicquotes

Source: Internet
Author: User
This article provides a detailed analysis of magicquotes in php. For more information, see

This article provides a detailed analysis of magic quotes in php. For more information, see

I checked the following manual. For php magic quotes, several common settings are as follows: magic_quotes_gpc, magic_quotes_sybase, and magic_quote_runtime. These functions are in php. configured in ini. We can see from the manual that these features have been abolished since php5.3, So we strongly recommend that you do not use them. Hong Kong servers are rented in php. ini.

These functions are used to escape data. When SQL injection is prevented, many people write as follows:

The Code is as follows:


If (! Get_magic_quotes_gpc ()){
$ Post = addslashes ($ post );
}


If they are enabled, the website space will automatically escape single quotes ('), double quotes ("), backslash (\), and NUL (null characters ), in fact, it is equivalent to calling the addslashes function. You may say that this is not very good. It is more secure. But, do you consider code portability in website space? In addition, do you need to escape all gpc ($ _ GET, $ _ POST, $ _ COOKIE) data? What is the overhead? The following is a detailed description of Magic Quotes in the manual:

1. magic_quotes_gpc

Magic_quotes_gpc is used to set the magic reference status of GPC ($ _ GET, $ _ POST, $ _ COOKIE) ($ _ ENV is also included in PHP4 ). When it is enabled, all single-quote, double quotation marks, backslash, and NUL's will be automatically escaped by the backslash. When magic_quote_sybase is on enabled, only singgle-quote will be escaped as ''by single quotation marks, double quotation marks, backslash, and NUL's will not be affected.

2. magic_quote_runtime

Magic_quote_runtime if this option is enabled, many functions that return external data (Database, text) will be escaped by backslash. If magic_quote_sybase is enabled, only single-quotes are escaped.

3. magic_quotes_sybase

Magic_quotes_sybase if this option is enabled, when magic_quotes_gpc and magic_quotes_runtime are enabled, single quotation marks are transferred by single quotation marks instead of backslash \ escape. At the same time, this setting will completely overwrite the magic_quotes_gpc settings, even if magic_quotes_gpc is set to on, double quotation marks ", backslash \ and NUL's will not be escaped.

Related Article

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.