MAGIC_QUOTES_GPC dynamic shutdown in PHP is not an issue

Source: Internet
Author: User
Browsing the online project yesterday, a problem was found: a backslash was added to the quotation marks in some text output, such as:

The quotation marks are much more \ "backslash \"

Judging from the results of the page, the guess should be the reason why the MAGIC_QUOTES_GPC configuration in PHP is turned on. Then check the next program, found in the portal file, has been dynamically closed this configuration:

Ini_set (' magic_quotes_gpc ', ' Off ');

Why didn't it take effect?

After some searching, the colleague helped to find the reason because the request was parsed before I changed the configuration dynamically, so the modification was not effective for the time of the request.

See the following page, a colleague also encountered the same problem:

https://bugs.php.net/bug.php?id=32867

MAGIC_QUOTES_GPC is applied while parsing the request before your PHP script gets control So while your can change this set Ting in your script, it won ' t has any effect.

Since there are multiple projects on the server, we cannot directly modify the configuration of the php.ini in order to not affect other projects, so we use the code written by strangers vs recall and recursively process the GPC content:

if (Ini_get (' MAGIC_QUOTES_GPC ')) {        function stripslashesrecursive (array $array)        {                   foreach ($array as $k = > $v) {                        if (is_string ($v)) {                                $array [$k] = stripslashes ($v);                        } else if (Is_array ($v)) {                                $array [$k] = str Ipslashesrecursive ($v);                        }                   }                   return $array;        }               $_get   = stripslashesrecursive ($_get);        $_post  = stripslashesrecursive ($_post);}
  • 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.