Home  >  Article  >  Web Front-end  >  Code to determine whether the user is online_javascript skills

Code to determine whether the user is online_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:09:531434browse

Consider two situations:
(1) The user closes the browser or is redirected to other web pages

Copy the code The code is as follows:



Explanation: null.php is used to set the user status to offline
(2) The user no longer browses this website for a long time
Idea: Create a table active_stat with attributes including userid, lasttime, and nowtime. Every time the user opens this website, change lasttime to the current time now(), change nowtime to the current time every 1 minute, and determine whether nowtime-lasttime is greater than 20 minutes. If it is greater, modify the user status to offline
Copy code The code is as follows: