PHP - 魔术引用gpc和stripslashes问题

时间:2010-11-30 15:32:19

标签: php stripslashes magic-quotes-gpc

好的,我的托管公司magic_quotes_gpc已转为ON,我使用stripslashes()编写了我的PHP脚本以准备此问题。但现在托管公司表示将关闭magic_quotes_gpc,我想知道现在当stripslashes()出现时我的数据会发生什么,我应该通过所有数百万行代码并摆脱它stripslashes()的?或单独留下stripslashes()功能?我会留下stripslashes()破坏我的数据吗?

3 个答案:

答案 0 :(得分:9)

您的代码应该使用get_magic_quotes_gpc来查看是否启用了魔术引号,并且只有条带斜线才会被启用。您应该在一个地方运行一个类似于以下内容的代码块,由您的所有脚本共享;如果你在多个地方使用stripslashes,那你做错了。

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

答案 1 :(得分:1)

我会开始浏览并删除stripslashes()。您可以提前测试magic_quotes_gpc并仅在需要时调用stripslahes()来提前执行此操作。

答案 2 :(得分:0)

meagar有正确答案。

但是为了遍历这种情况,你需要像Notepad ++这样的文件功能。复制一段meagar代码并搜索stripslashes()