开发者

Close session on certain conditions

Right now i am using sessions to login user and pull necessary info. for some reason on Safari, if the user doesn't is inactive for a long time or closes the window without signing out it gives a redirect error. Is there a way i can sign the user out automatically if they close the tab or window without signing out?

              The page开发者_Go百科 isn't redirecting properly



           Firefox has detected that the server is redirecting the request for this address
           in a way that will never complete.


           This problem can sometimes be caused by disabling or refusing to accept
  cookies.


The direct answer to your question is a qualified "no". You can add an unload event to a page and send out an AJAX query when it fires (as the user closes the browser or tab, or navigates away from the page), but some browsers stop all pending requests as part of sending out the new request. Plus, you'd have to make some kind of allowance for when the user is simply navigating around your own site, which will fire the same events as it would if he or she were to navigate away. And, what if they have your site open in multiple windows or tabs?

All in all, I think you're better off addressing the "redirect error" that you mentioned. This kind of work around is prone to problems of its own - you'd be trading problems for problems.


Maybe you can create a cookie that will expire when the browser is closed, and when someone re-opens the website with a re-opened browser and doesn't have that cookie, end the session?

I believe casablanca is right, though, so the php session should end when the browser is closed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜