Home >Backend Development >PHP Tutorial >Magic_quotes_gpc dynamic closing problem in PHP is invalid_PHP tutorial
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 marksJudging 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')) {