开发者

cookie not saved in the browser before the next request

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 craz开发者_如何学运维y) 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


It's probably not a problem of saving the cookie, but a problem of aborting the request.

  • browser sends request to server
  • server handles request, prepares new cookie, invalidates old cookie
  • you hit F5
  • browser aborts request, issues new request with old cookie
  • server sends response including new coo--
  • server receives new request with old, invalid cookie

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜