Multiple solutions for browser shutdown issues that fail session

Source: Internet
Author: User
Tags exit time interval
Close the browser directly (or forced to close the browser process, panic, etc.), the server can not handle the user's request to quit the site, this will lead to session invalidation, the following sorted out some solutions, interested friends can refer to ha

If the user does not click on the "Exit" link of the website and directly closes the browser (or forcibly closes the browser process, crashes, etc.), the server cannot process the user's request to exit the site, as follows:

Mode 1: add hidden iframe in each page, refresh the IFRAME periodically in the way of asynchronous refresh, such as every 10S refresh once, when the server has not received the user's refresh request in a certain time, the user is considered to have exited
Advantages: In a short period of time to determine whether the user has quit the disadvantage: increase the number of user requests, the consumption of server resources are larger

Mode 2: use cookies to save user login information, do not set the expiration time of the cookie, when the browser is closed, the cookie automatically expires
Advantages: Easy to handle: The user's browser does not necessarily support cookies and is not implemented in this way

Mode 3: Add the OnUnload event to the page and automatically jump to the exit page when the browser is closed (loginout.action)
Advantages: When exiting, can handle the shortcoming in time: When the user opens multiple pages, closing any one page may cause the user to exit

Mode 4: record the user's every operation time (including page refresh, submit form, etc.), in the database with the job every time to check the last operation time, when the operation time is greater than a certain value, it is considered that the user has exited
Advantages: No matter what kind of abnormal exit, can handle the disadvantage: the time interval for checking is not easy to determine, if the user online, when the long time does not operate, will also think that the user has exited

Mode 5: wait for session expiration
Pros: You don't have to do any job disadvantage: The user can log in while you are waiting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.