找出Cookie的设置路径

时间:2016-08-25 15:25:18

标签: php cookies

我有一些饼干问题 事情进展顺利,然后我们做了一个网站更新,我启用了cookie的安全性,现在记住我的cookie不再起作用了。

我不确定我是否有一些设置在一个级别而不是另一个级别的cookie,我想要清除所有的cookie以便重新开始。

这是我清晰的脚本:(基于这个答案:https://stackoverflow.com/a/2310591/356438

<pre>
<?
    echo "Before \n\n";
    print_r(explode(";",$_SERVER['HTTP_COOKIE']));
    // unset cookies
    if (isset($_SERVER['HTTP_COOKIE'])) {
        $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
        foreach($cookies as $cookie) {
            $parts = explode('=', $cookie);
            $name = trim($parts[0]);
            setcookie($name, '', 1);
            setcookie($name, '', 1, '/');
        }
    }
    echo "\n\n After \n\n";
    print_r(explode(";",$_SERVER['HTTP_COOKIE']));
?>
</pre>

当我在站点根目录上运行它时,我得到了这个输出:

Before 

Array
(
    [0] => Test=test
    [1] =>  Test2=test2
    [2] =>  lastvisit=1468329822
    [3] =>  lastvisit=1472134053
    [4] =>  __utma=210079566.190815705.1466193830.1472067428.1472133823.168
    [5] =>  __utmc=210079566
    [6] =>  __utmz=210079566.1469538895.71.3.utmcsr=website.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    [7] =>  logname=AndyD273
    [8] =>  logid=8d3f09f7fc83eb0592f3d24d332ca85d
)


 After 

Array
(
    [0] => Test=test
    [1] =>  Test2=test2
    [2] =>  lastvisit=1468329822
    [3] =>  lastvisit=1472134053
    [4] =>  __utma=210079566.190815705.1466193830.1472067428.1472133823.168
    [5] =>  __utmc=210079566
    [6] =>  __utmz=210079566.1469538895.71.3.utmcsr=website.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    [7] =>  logname=AndyD273
    [8] =>  logid=8d3f09f7fc83eb0592f3d24d332ca85d
)

当它在包含成员区域的目录中运行时,我得到了这个:

Before 

Array
(
    [0] => lastvisit=1466790329
    [1] =>  Test=test
    [2] =>  Test2=test2
    [3] =>  lastvisit=1468329822
    [4] =>  lastvisit=1472134053
    [5] =>  __utma=210079566.190815705.1466193830.1472067428.1472133823.168
    [6] =>  __utmc=210079566
    [7] =>  __utmz=210079566.1469538895.71.3.utmcsr=website.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    [8] =>  logname=AndyD273
    [9] =>  logid=8d3f09f7fc83eb0592f3d24d332ca85d
)


After 

Array
(
    [0] => lastvisit=1466790329
    [1] =>  Test=test
    [2] =>  Test2=test2
    [3] =>  lastvisit=1468329822
    [4] =>  lastvisit=1472134053
    [5] =>  __utma=210079566.190815705.1466193830.1472067428.1472133823.168
    [6] =>  __utmc=210079566
    [7] =>  __utmz=210079566.1469538895.71.3.utmcsr=website.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    [8] =>  logname=AndyD273
    [9] =>  logid=8d3f09f7fc83eb0592f3d24d332ca85d
)

我正在设置cookie,以防这不是正确的方法:

<?
setcookie("logname", $username, time()+(60*60*24*100), "/", ".website.com", true, true);
?>

我希望有办法看到所有的Cookie以及它们设置的路径,这样我就可以确保我做得对。

修改

我添加了域名部分:

setcookie($ name,'',1,'/','。website.com');

并将其清除为:

Array
(
    [0] => lastvisit=1466790329
    [1] =>  Test=test
    [2] =>  Test2=test2
    [3] =>  lastvisit=1468329822
)

编辑2:
安全证书似乎是有序的 enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

因此,在查找https证书信息后,我记得Chrome列出了所有Cookie,包括路径和域信息,这有助于我弄清楚我做错了什么。

修正了错误,清除了坏饼干,现在一切正常。

帮助您获得最准确的信息。