PHP - magic quotes gpc and stripslashes question

2019-04-13 15:09发布

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?

3条回答
放荡不羁爱自由
2楼-- · 2019-04-13 15:23

meagar has the correct answer.

But to traverse the situation, you need something like Notepad++ with a Search within files function. Copy a snippet of meagar's code and search for stripslashes()

查看更多
太酷不给撩
3楼-- · 2019-04-13 15:34

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);
}
查看更多
叼着烟拽天下
4楼-- · 2019-04-13 15:38

I would start going through and removing stripslashes(). You can do this ahead of time by testing for magic_quotes_gpc and only calling stripslahes() if it is needed.

查看更多
登录 后发表回答