PHP disables page cache output

Source: Internet
Author: User

For Magic quotes, PHPer is a common issue. I accidentally saw an article today, combined with PHP Manual and his reply, and made a simple summary here.

In short, Magic quotes automatically escapes the input data when it is enabled. All single quotation marks (), double quotation marks ("), backslash, and NULL characters are escaped (with a backslash added). In fact, this operation essentially calls the addslashes function.

Why use Magic quotes?
Convenient
The idea of PHP designers at the beginning of design is to be able to program quickly and conveniently. For example, Magic quotes automatically escapes data when inserting a database, which is very convenient.

Good for beginners
Magic quotes helps beginners take away the security risks of scripts to a certain extent. For example, if you enable Magic quotes without any protection measures, there will be fewer risks, such as injection problems. Of course, using this method alone cannot completely prevent such security issues.

"I have no permission to close it"
Obviously, you may have realized this problem, but the host space is not completely controlled by yourself.

Why not use Magic quotes?
Portability
Whether or not this function is enabled affects the portability of scripts because it affects subsequent data filtering operations.

Performance problems
It is escaped before obtaining all external data, which will undoubtedly increase the runtime cost (and not all data needs to be escaped ).

Confusions
As mentioned above, not all data needs to be escaped. One possible scenario is when you use the stripslashes function "crazy" to get unescaped data.

PHP6 is not supported
PHP designers have clearly realized their "errors", so they have been abandoned in PHP6.

How to disable Magic quotes
In my opinion, using the php. ini configuration file to globally disable Magic quotes is the most reliable. Refer to the following code

; Magic quotes for incoming GET/POST/Cookie data. magic_quotes_gpc = Off; Magic quotes for runtime-generated data, e.g. data from SQL, from exec (), etc. magic_quotes_runtime = Off; Use Sybase-style magic quotes (escape with instead ). magic_quotes_sybase = Off. However, online hosts may not allow you to modify php. ini file, you can use. disable the htaccess file and add the following code:

Php_flag magic_quotes_gpc Off the above portable code, whether or not magic_quotes is disabled, the data must be consistent. The following code can help you

<? Phpif (get_magic_quotes_gpc () {function stripslashes_deep ($ value) {$ value = is_array ($ value )? Array_map (values, $ value): stripslashes ($ value); return $ value; }$ _ GET = array_map (stripslashes_deep, $ _ GET); $ _ POST = array_map (stripslashes_deep, $ _ POST); $ _ COOKIE = array_map (stripslashes_deep, $ _ COOKIE); $ _ REQUEST = array_map (stripslashes_deep, $ _ REQUEST );}

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.