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 VS2010通过OnCtlColor函数改变radio控件字体的颜色为白色,但是程序运行后发现不起作用,怎么办?
  • ¥15 Qt中实现子线程和管理线程类之间实时通信
  • ¥15 cacls 命令如何解除锁定文件夹?
  • ¥50 C++使用TWAIN协议如何实现A3幅面扫描仪扫描A4横向
  • ¥15 如何在sql server里完成筛选
  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思