Why backslashes are being added to all the $_GET, $_POST automatically?

耗尽温柔 提交于 2019-12-12 05:49:49

问题


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.

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
?>

How to turn off this thing?

Thanks


回答1:


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.

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));
}



回答2:


You have to disable magic_quotes_gpc.




回答3:


It's a (deprecated) security feature called "magic quotes," and it's possible to turn it off.



来源:https://stackoverflow.com/questions/4359854/why-backslashes-are-being-added-to-all-the-get-post-automatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!