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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?