Invalid dynamic shutdown of magic_quotes_gpc in PHP _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
In PHP, the dynamic shutdown of magic_quotes_gpc is invalid. Yesterday, I browsed online projects and found a problem: some text outputs have a backslash before the quotation marks. for example, if the quotation marks have more content than the backslash, I can see from the results displayed on the page, yesterday, I browsed online projects and found a problem: some text outputs have a backslash before the quotation marks, for example:

Too many quotation marks \ "backslash \"

According to the results displayed on the page, it is suggested that the magic_quotes_gpc configuration in PHP is enabled. Then I checked the program and found that the configuration has been dynamically disabled in the entry file:

Ini_set ('Magic _ quotes_gpc ', 'off ');

Why does it not take effect?

After some searching, my colleague helped me find the reason. it turned out that the request had been resolved before I dynamically modified the configuration. Therefore, the modification did not take effect for the current request.

For details, see the following webpage. one of the colleagues 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 you can change this setting in your script, it won't have any effect.

In view of the existence of multiple projects on the server, we cannot directly modify the configuration of php. ini in order not to affect other projects. Therefore, we use the code compiled by Momo vs recall to 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] = stripslashesRecursive ($ v );
}
}
Return $ array;
}

$ _ GET = stripslashesRecursive ($ _ GET );
$ _ POST = stripslashesRecursive ($ _ POST );
}

The quotation marks contain \ backslash \ single. from the page display results ,...

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.