PHP-魔术引号gpc和stripslashes问题 [英] PHP - magic quotes gpc and stripslashes question
问题描述
好吧,我的托管公司已将magic_quotes_gpc
转换为ON
,为此我使用stripslashes()
编写了PHP脚本.但是现在托管公司说它将关闭magic_quotes_gpc
,我想知道当存在stripslashes()
时我的数据现在将要发生什么,如果我要遍历数百万行代码并摆脱stripslashes()
?还是不使用stripslashes()
函数?会离开stripslashes()
破坏我的数据吗?
Okay my hosting company has magic_quotes_gpc
turned ON
and I coded my PHP script using stripslashes()
in preparation of this. But now the hosting company says its going to turn magic_quotes_gpc
OFF and I was wondering what will happen now to my data now when stripslashes()
is present should I go through all my millions of lines of code and get rid of stripslashes()
? or leave the stripslashes()
function alone? will leaving the stripslashes()
ruin my data?
推荐答案
您的代码应使用 get_magic_quotes_gpc
查看是否启用了魔引号,并且只有反斜杠才被使用.您应该在一个地方运行一个与以下代码相似的代码块,并由所有脚本共享该代码块;如果您在多个地方使用stripslashes
,则说明操作有误.
Your code should use get_magic_quotes_gpc
to see if magic quotes are enabled, and only strip slashes if they are. You should run a block of code similar to the following in exactly one place, shared by all your scripts; if you're using stripslashes
in multiple places you're doing it wrong.
// recursively strip slashes from an array
function stripslashes_r($array) {
foreach ($array as $key => $value) {
$array[$key] = is_array($value) ?
stripslashes_r($value) :
stripslashes($value);
}
return $array;
}
if (get_magic_quotes_gpc()) {
$_GET = stripslashes_r($_GET);
$_POST = stripslashes_r($_POST);
$_COOKIE = stripslashes_r($_COOKIE)
$_REQUEST = stripslashes_r($_REQUEST);
}
这篇关于PHP-魔术引号gpc和stripslashes问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!