2013-05-14 26 views
0

它在共享服务器上带有魔力报价的***中很痛苦,我放弃上传另一个php.ini来覆盖共享主机php.ini,因为其他问题发生,(PDO在配置但未加载等)我尝试.htaccess给出500错误。

,所以我发现这个解决方案是相当不错的,并且效果很好 How to turn off magic quotes on shared hosting?

if (in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) 
{ 
    $_POST = array_map('stripslashes', $_POST); 
    $_GET = array_map('stripslashes', $_GET); 
    $_COOKIE = array_map('stripslashes', $_COOKIE); 
} 

,直到我开始张贴阵列到服务器

<select name="gropu[]"> 
<option value="1">2</option> 
<option value="2">1</option> 
<option value="3">3</option> 
</select> 

然后我有errro以下

Warning: stripslashes() expects parameter 1 to be string, array given in index.php on line 18 

请帮助我,这真的是一个noying我同时发展本地主机上的东西确定,一旦上传到服务器上,它只是所有的错......

+0

还要注意,'parse_str'功能依赖于魔术引号选项,所以你必须,如果你正在使用的功能,以解除引用他们的结果。 – 2013-05-14 00:44:14

回答

1

我通常在初始化运行此:

// attempt to disable 'magic quotes' at runtime 
@ini_set('magic_quotes_runtime', 0); 
@ini_set('magic_quotes_sybase', 0); 

// strip slashes if that didn't work 
if(get_magic_quotes_gpc()){ 
    function _strip_slashes_ref(&$var){ 
    $var = stripslashes($var); 
    } 

    array_walk_recursive($_POST, '_strip_slashes_ref'); 
    array_walk_recursive($_GET,  '_strip_slashes_ref'); 
    array_walk_recursive($_COOKIE, '_strip_slashes_ref'); 
    array_walk_recursive($_REQUEST, '_strip_slashes_ref'); 
} 

魔术的报价在5.4去除,所以你可能要做到这一点只有:

version_compare(PHP_VERSION, '5.4.0') < 0 
+0

真的吗?你可以杀死它在运行时?是的,我认为我使用的共享主机少于5.4 -_-感谢帮助队友 – Bruce 2013-05-14 00:39:54

+0

[显然你不能](http://php.net/manual/en/security.magicquotes.disabling.php )。 ''magic_quotes_runtime'可以在运行时禁用,虽然 – 2013-05-14 00:44:33

+0

此array_walk_recursive工作比array_map好得多 – Bruce 2013-05-14 02:09:38