【发布时间】:2014-03-06 03:43:48
【问题描述】:
我目前正在开发一个在 Firefox 上运行的网站。
我的程序中有一个拦截器,用来拦截所有请求,判断cookie值是否为登录状态。如果未登录状态则重定向到登录页面。
当 Firefox 启动时,我的 Firefox 设置为“显示我上次的窗口和标签页”。
我登录网站并直接关闭 Firefox。但是当我重新打开 Firefox 时,它仍然处于登录状态。
我应该怎么做才能避免这个问题?
【问题讨论】:
我目前正在开发一个在 Firefox 上运行的网站。
我的程序中有一个拦截器,用来拦截所有请求,判断cookie值是否为登录状态。如果未登录状态则重定向到登录页面。
当 Firefox 启动时,我的 Firefox 设置为“显示我上次的窗口和标签页”。
我登录网站并直接关闭 Firefox。但是当我重新打开 Firefox 时,它仍然处于登录状态。
我应该怎么做才能避免这个问题?
【问题讨论】:
本主题可能会让您深入了解 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;
【讨论】: