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 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示