2013-04-22 40 views

回答

4

最有可能的原因是您打开了magic quotes。你应该:

  • 升级到PHP 5.4
  • 在你的PHP配置文件disable them
  • 禁用它们在你的Apache配置(同一个链接)
  • (最后一招)测试以查看它们是否已打开,然后在输入上运行stripslashes
+0

咦,那很烂(我不能改变服务器的配置,所以我现在必须使用'php.ini'的)。谢谢! – chacham15 2013-04-22 20:09:04

1

如果你不能保证环境,让重新配置,你可以使用这个可重用的代码递归到$ _GET挖,$ _ POST阵列或的stripslashes清除它们:

class de_slasher { 

    function recursive_stripslashes($a) { 
     $b = array(); 
     foreach($a as $k => $v) { 
      $k = stripslashes($k); 
      if(is_array($v)) { 
       $b[$k] = $this->recursive_stripslashes($v); 
      } else { 
       $b[$k] = stripslashes($v); 
      } 
     } 
     return($b); 
    } 

    function check_and_fix_magic_quotes(&$array) { 
     if(get_magic_quotes_gpc()) { 
      $array = $this->recursive_stripslashes($array); 
     } 
    } 

    function __construct($auto = false) { 
     if($auto === true) { 
      $this->check_and_fix_magic_quotes($_POST); 
      $this->check_and_fix_magic_quotes($_GET); 
     } 
    } 
} 

要使用,只需包含该类,并调用$slasher = new de_slasher(true);来自动清理$ _GET和$ _POST。这只有在魔术引号设置打开的情况下才会发生。如果实例化类没有“真正”的参数,那么你可以选择深层过滤器的任何阵列:

$my_array = array("name" => "Herbert\'s Apple"); 
$slasher = new de_slasher(); 
$slasher->check_and_fix_magic_quotes($my_array);