为什么反斜杠会自动添加到所有$ _GET和$ _POST? [英] Why backslashes are being added to all the $_GET, $_POST automatically?
问题描述
我有一个使用cPanel / Whm / CentOS 5.5的vps,问题是发送到我服务器的所有参数都被加了斜杠,我检查了PHP配置,发现所有
I have a vps with cPanel/Whm/CentOS 5.5 and the problem is that all parameters sent to my server are being addslashed, I've checked out the PHP configuration and i found out that all the magic quotes are turned off and i don't know what causes this.
我的代码很干净,我知道其中的每一点,而且我没有任何东西 addslashes()
或某些此类功能。我只想按原样接收参数。
My code is so clean and i know every bit of it and i don't have any addslashes()
or some sort of these functions. i only want to receive the parameters as they are.
URL: test.php?text=blah" ' " 'blah
<?php
echo $_GET["text"]; // Output blah\" \' \" \'blah
?>
如何关闭此功能?
谢谢
推荐答案
这是 magic_quotes_gpc 变量(这是关闭它的第一个位置)。您应该检查一下您是否在查看正确的文件。
It's the magic_quotes_gpc variable in your php.ini (this is the first place to turn it off). You should really check of you are looking at the right file.
您也可以在.htaccess或运行时中关闭它。但是,如果您的主机不允许您执行上述任何一项操作,则可以使用以下函数,无论当前设置如何,该函数都将发出指令。
You can also turn it off in .htaccess or at runtime I believe. But if your host doesn't won't let you do either of these things you can use the following function that will word regardless of the current setting.
if(get_magic_quotes_gpc()) {
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
function stripslashes_deep($value) {
return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
}
这篇关于为什么反斜杠会自动添加到所有$ _GET和$ _POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!