dongpo5264 2011-11-23 16:58
浏览 39
已采纳

为什么php阅读反斜杠?

I have a code that saves data to a cookie. and the data saved in the cookie is like this:

(%22Lynyrd%20Skynyrd%22%3D%3Earray(%226983887641%22)%2C%20(%22Rod%20Stewart%22%3D%3Earray(%2259088763306%22)%2C%20(%22Led%20Zeppelin%20Official%22%3D%3Earray(%22131572223581891%22)%2C%20(%22Black%20Sabbath%22%3D%3Earray(%2256848544614%22)%2C%20(%22Hadag%20Nahash%20%D7%94%D7%93%D7%92%20%D7%A0%D7%97%D7%A9%22%3D%3Earray(%22116542622632%22)%2C%20

and when i read it with this php:

<?php
    if (isset($_COOKIE["currentsearchctrl"])) {
        $cookz = $_COOKIE["currentsearchctrl"];
        echo $cookz;

    } else {
        echo 'cookie not set';
    } ?>

It returns with this:

(\"Lynyrd Skynyrd\"=>array(\"6983887641\"), (\"Rod Stewart\"=>array(\"59088763306\"), (\"Led Zeppelin Official\"=>array(\"131572223581891\"), (\"Black Sabbath\"=>array(\"56848544614\"), (\"Hadag Nahash הדג נחש\"=>array(\"116542622632\"),

The problem are the backslashes. I was going to: $data = array($cookz); but it doesn't work.

any ideas?

  • 写回答

4条回答 默认 最新

  • dpr77335 2011-11-23 17:07
    关注

    It's because magic quotes is enabled on the host. It's a horrible "feature" and everybody wishes it would just die.

    If you can edit php.ini on the server, set magic_quotes_gpc = Off and magic_quotes_runtime = Off.

    Otherwise, if Apache is the HTTP server, there is a .htaccess trick you can use, documented here.

    Otherwise, you have to use stripslashes() to get data back to normal. Here is the include'd script I use to disable magic quotes when it isn't possible to disable it another way:

    if (get_magic_quotes_gpc()) {
        function array_stripslashes(&$array) {
            foreach($array as $k => $v) {
                if (is_array($v)) {
                    array_stripslashes($array[$k]);
                } else {
                    $array[$k] = stripslashes($v);
                }
            }
        }
        array_stripslashes($_GET);
        array_stripslashes($_POST);
        array_stripslashes($_COOKIE);
        array_stripslashes($_REQUEST);
    }
    
    set_magic_quotes_runtime(0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)