【问题标题】:How to log out when I close the Firefox?关闭 Firefox 时如何注销?
【发布时间】:2014-03-06 03:43:48
【问题描述】:

我目前正在开发一个在 Firefox 上运行的网站。

我的程序中有一个拦截器,用来拦截所有请求,判断cookie值是否为登录状态。如果未登录状态则重定向到登录页面。

当 Firefox 启动时,我的 Firefox 设置为“显示我上次的窗口和标签页”。

我登录网站并直接关闭 Firefox。但是当我重新打开 Firefox 时,它仍然处于登录状态。

我应该怎么做才能避免这个问题?

【问题讨论】:

    标签: firefox cookies


    【解决方案1】:

    本主题可能会让您深入了解 Firefox cookie 处理:Firefox session cookies

    此外,问题中没有明确说明您想要实现什么。如果您有兴趣自己解决问题,请考虑更改 Firefox 模式。如果您想为任何基于 Firefox 的网站用户修复它,请考虑提及您用于创建网站的技术。

    更新: One the one hand,

    未在 cookie 上指定 Expires 值将导致 cookie 在浏览器会话结束时即用户关闭浏览器时被删除。

    另一方面,正如 post above 中所述,Firefox 处理 cookie 的方式略有不同。

    因此,您可以使用短 cookie Expires 值并在用户在线时定期更新它。

    您也可以use unload and onbeforeunload events,它可以帮助您通过关闭标签或转到另一个地址来检测离开网站。

    以下模型也是可能的:

    在客户端:

    once a user opens a new tab, 
        some ID is given to this in js code, 
        and that ID is sent to the server as an ID to create;
    once a tab is closed, 
        its ID is sent to server by js code as an ID to remove; 
    

    在服务器端:

    once a server receives an ID to create,
        it generates a session ID and returns it to a client;
    once a server receives an ID to remove,
        it checks, if there are any more tab IDs left,
            if there are some, it just removes a tab ID from an array of those IDs;
            if there are no more, it removes the session and clears its tab IDs array;
    

    【讨论】:

    • 非常感谢。我想为任何基于 Firefox 的网站用户修复它,但不知道。我还测试了 stackoverflow 网站,它在会话恢复时会退出状态,这是怎么做的?
    • 亲爱的@user3381989,请检查更新。它可能包含一些有用的信息!
    • 致 Danek:太好了,非常有用!因为 Firefox 具有恢复所有会话 cookie 的功能,所以我认为“使用短 cookie 过期值并在用户在线时定期更新”会work.Like: 设置 cookie 的 Max-Age 为 1 分钟,每 30 秒更新一次。
    猜你喜欢
    • 1970-01-01
    • 2022-11-20
    • 2017-12-28
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多