【问题标题】:Any idea why I have to click the logout button twice to logout?知道为什么我必须单击注销按钮两次才能注销吗?
【发布时间】:2013-01-10 17:43:02
【问题描述】:

This is my code for logout.php

当我在我正在构建的网页上点击 LOGOUT 时,我必须点击两次才能注销,知道为什么吗?

【问题讨论】:

标签: php html css web-services web


【解决方案1】:

您似乎同时使用了会话和 cookie,可能是为了“记住我”功能。但是,注销脚本一次只删除一个。

尝试删除else if中的else

if (session exists)
{
    destroy session
}

if (cookie exists)
{
    delete cookie
}

【讨论】:

    【解决方案2】:

    第一次注销时,if 会运行,从而破坏会话。下次您注销时,else 会运行,删除 cookie。

    看看PHP - session_destroy,有一个关于如何处理的例子。

    你也可以一次运行,只做两个独立的ifs

    if (isset($_SESSION['user_id']) {
    ...
    }
    
    if (isset($_COOKIE['user_id']) {
    ...
    }
    

    【讨论】:

    • 啊,谢谢。真的累了。大概应该去睡觉了。连else语句都没看到哈哈。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    • 2022-01-22
    • 1970-01-01
    • 2021-01-29
    • 2015-07-02
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多