【问题标题】:Expired session cookie appears to still exist过期的会话 cookie 似乎仍然存在
【发布时间】:2012-11-07 18:18:50
【问题描述】:

我正在尝试删除会话 cookie。这些是我正在遵循的步骤

        // Find the session - I believe this is doing a resume rather than starting a fresh session thus identifying the session.
        session_start();

        // Unset all the session variables enmasse by assigning an empty array
        $_SESSION = array();

        // find the session name that has been allocated then destroy the session cookie
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'', time()-42000, '/');
           // set content of found session to null, with a past time, at the root
        }

        // Destroy the session 
        session_destroy();

这肯定会让我退出。但是实际的 cookie 仍然存在,可以在浏览器 (firefox) 中查看。

$_COOKIE[session_name()]

似乎返回的是加密的内容字符串,而不是会话名称。

问题:

如果 $_COOKIE[session_name()] 不是获取会话名称的正确方法,那是什么?

我应该设置一个 session_name 而不是让它默认吗?

我看到会话是因为它正在等待某种垃圾收集吗?

【问题讨论】:

    标签: php session-cookies


    【解决方案1】:

    你可能想看看这个页面:

    http://php.net/manual/en/function.session-destroy.php

    为了完全终止会话,例如注销用户,还必须取消设置会话 ID。如果使用 cookie 传播会话 id(默认行为),则必须删除会话 cookie。 setcookie() 可以用于此。

    基于此,您可能希望使用 session_id() 而不是 session_name()

    【讨论】:

    • 不太确定这是否正确,请参阅:php.net/manual/en/function.session-destroy.php
    • session_id 确实不起作用,它似乎返回 null。我想知道我对 root 的依赖,即“/”是否有问题,而不是获取和使用 cookie 参数
    • 我以前阅读过此文档,但没有逐字应用它。我刚刚尝试过这样做,但没有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多