doujiang2020 2013-05-14 00:33
浏览 43
已采纳

magic_quotes_gpc关闭共享主机与$ _POST数组

It's pain in the *** with magic quote on on the share server, and I am giving up on upload another php.ini to overwrite the share host php.ini, because then other problem occurr, (PDO in configure but not loaded and ect) I tried .htaccess which give a 500 error.

so i have found this solution is pretty good and works well 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 );
}

Until i start to post array to the server

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

then i have the following errro

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

Please help me on this, it really annoying me while developing something ok on the localhost and once upload to the server it just all wrong...

  • 写回答

1条回答 默认 最新

  • doujieyu7062 2013-05-14 00:35
    关注

    I usually run this on initialization:

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

    Magic quotes are removed in 5.4, so you might want to do this only if:

    version_compare(PHP_VERSION, '5.4.0') < 0
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?