下次请求之前cookie未保存在浏览器中
我一直在用 php 开发登录系统。这东西运行得很好,但我有一个我无法摆脱的有趣行为。基本上,如果我执行多次快速刷新(疯狂地按 f5),我就会注销。
这是因为系统依赖于服务器在每次发出请求时刷新浏览器中的 cookie。我的感觉是,当刷新非常快时,在请求N返回的cookie尚未保存在浏览器中之前发出了请求N+1。这会导致提供的 cookie 中的信息与服务器期望的信息不一致。
事实上,如果我定期按 f5(例如每秒一次),则可以保持经过身份验证的状态,并且一切正常。
Any1曾经遇到过类似的问题吗?据您所知,保存cookie的进程是在浏览器的不同线程中执行的吗?我想这可以解释我的问题。
谢谢大家
I have been working on a login system in php. The thing works pretty well but I have 1 funny Behavior I cant get rid of. Basically if I perform many quick refreshes (hitting f5 like crazy) I get logged out.
This is because the system relies on the server refreshing a cookie in the browser every time a request is issued. I have the feeling that when refreshing very quickly, the request N+1 is issued before the cookie returned by the request N has been saved in the browser. This leads to a misalignment of the info in the provided cookie and the info expected by the server.
In fact if I hit f5 regularly, say once a second, the authenticated state is maintained and everything works fine.
Any1 has ever had a similar problem? As far as u know, is the process saving cookies executed in a different thread in the browser? That would explain my problem I guess.
gracias hombres
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能不是保存cookie的问题,而是中止请求的问题。
是的,那个发生。为了避免这导致问题,您可能希望允许重复使用最后两个 cookie,但这需要一些手动会话处理。
It's probably not a problem of saving the cookie, but a problem of aborting the request.
And yeah, that happens. To avoid this causing problems you might want to allow the last two cookies to be reused, but that requires some manual session juggling.