Home >Backend Development >PHP Tutorial >Magic_quotes_gpc dynamic closing problem in PHP is invalid_PHP tutorial

Magic_quotes_gpc dynamic closing problem in PHP is invalid_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:58:46869browse

Browsing online projects yesterday, I found a problem: there is an extra backslash before the quotation marks in some text output, such as:

There are too many "backslashes" in the quotation marks

Judging from the results displayed on the page, it is guessed that the magic_quotes_gpc configuration in PHP is turned on. Then I checked the program and found that in the entry file, this configuration has been dynamically closed:

ini_set('magic_quotes_gpc', 'Off');

Why doesn’t it take effect?

After some searching, my colleagues helped me find the reason. It turned out that the request had been parsed before I dynamically modified the configuration, so the modification did not take effect for the current request.

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

In view of the fact that there are multiple projects on the server, in order not to affect other projects, we cannot directly modify the configuration of php.ini, so we used the code written by MOLU vs Memories 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);
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363784.htmlTechArticleBrowsing online projects yesterday, I found a problem: there is an extra backslash before the quotation marks in some text output , for example: There are too many backslashes in the quotation marks. Judging from the results displayed on the page,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn