PHP: how to set the timeout for the system
How to detect user action, from a website then we set the timeout for the system?
For exa开发者_运维问答mple, user login to the system, and the user do not do any action in the system for 30 minutes, then the system makes auto-logout for the user, then how can I know whether the user did any actions (like move the mouse, type the keyboard...)?
Normally by default, the session time is set as 30 minutes by the server itself, unless it's modified by the system administrator or by the programmer, as per the client's requirements. So you should not be worrying about this point at all.
Now regarding the user's any non-action, what I can say is that the server automatically time-outs the session internally, so that if the user performs any action after 30 minutes, the user will automatically need to re-login. But here there are two requirements:-
- The programmer must have properly set the restriction at the top of each user-specific page (like account details page, ...), so that the user can only perform actons hen he is logged in.
- The programmer must have properly written code to re-route the user to the login page, if the user wants to see the account details or user-specific action.
Hope it helps.
then how can I know whether the user did any actions (like move the mouse, type the keyboard...)?
These are all client side events. While you could trap some of these in Javascript and push a notification back serverside - you really don't want this kind of hassle. Just set up your session to timeout at 30 minutes.
Other answers have covered the ground regarding automatic session timeout.
If you want to keep the session alive if the users moves the mouse / presses the keyboard, you can implement an event listener (client side) and let it submit a "heartbeat" request (simple dummy GET
request to a valid endpoint) to the server in order to reset the timeout on the session. Thus, the session will be active for another 30 minutes.
精彩评论