How does javascript-php automatically exit after a user does not operate for a period of time?

Source: Internet
Author: User
Thinkphp is used to develop thinkphp. with its existing functions, the topic can end the session for a period of time (no matter whether the user has any operation, the user experience is definitely poor. do you have any operations to determine what the industry generally refers? 1. do you move the mouse for a while? 2. rat... thinkphp is used to develop thinkphp. with its existing functions, the topic can end the session for a period of time (no matter whether the user has any operation). However, the experience is definitely poor.

Determine whether the user has performed the operationIndustryWhat is the general situation?
1. do you move the mouse for a while?
2. why not click the mouse?
3...

I can use js to record these operations in the cookie and set the cookie expiration time. However, if the cookie expires, how can I end the session?

Reply content:

Thinkphp is used to develop thinkphp. with its existing functions, the topic can end the session for a period of time (no matter whether the user has any operation). However, the experience is definitely poor.

Determine whether the user has performed the operationIndustryWhat is the general situation?
1. do you move the mouse for a while?
2. why not click the mouse?
3...

I can use js to record these operations in the cookie and set the cookie expiration time. However, if the cookie expires, how can I end the session?

Solution 1
Server implementation principle: the user table sets an access timestamp for a record. when a user logs on, the timestamp is written, and the time interval is not required. each time a user accesses a page that requires logon permissions, first, check whether the time of the field is greater than the current time. if the value is greater than the current time, it indicates that the operation is in progress, and add the timestamp to the time when the operation is not performed, and then update the field again. Or use session instead of database records.
Solution 2
The front-end implementation principle uses HTML5 storage or cookies, which is consistent with solution 1, but the storage method has changed.
Comparison of solutions
Solution 1's database storage is not performing well. HTML5 is not compatible with low-version browsers, and js disabled by cookies will become invalid. Therefore, the session is suitable.

All I have done is to automatically exit 15 minutes after a user logs on. If the mouse is not moved, the mouse is clicked or the page is refreshed. You can setcookieWhen it expirescookieDelete. For reference only

Generally, there are no access requests. when there is a request, the backend can refresh the cookie and use the cookie to control expiration.

Of course, we can also use sessions to record the request time and determine whether the request has expired. If the frontend needs to force exit, the heartbeat signal can be used (of course, the heartbeat signal cannot record the request time ).

You can also combine the two. In short, there are a variety of methods, depending on how you want to use them.

If you have configured the session expiration time in php. ini, the cli will configure the session expiration time.Suicide.

Generally, the frontend listens to global events. each time an event is triggered, AJAX calls a session to keep the user session closed. Otherwise, the session will be released after the Expiration Time in php. ini is exceeded.

Don't worry about it. here is the ready-made:

Https://github.com/thorst/jqu...

There is a callback when you go to the idle status and restore the activation status. when you go to the idle status, send an xhr message to the server to end the session.

Generally, it is background control and set the session timeout time.

The user's operation time limit is the SESSION lifecycle. if the session cycle is assumed to be 24 minutes, if the user does not perform any operation after, after, in this case, the SESSION becomes invalid and you need to log on again. The limit is that the time difference between the two operations cannot exceed 24 minutes. In addition, if the COOKIE is invalid, the SESSION login is definitely unavailable. the user is definitely not logged on. The PHP garbage collection mechanism will automatically clear the SESSION file. if the SESSION is stored in redis, redis also has a method to destroy session data.

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.