How to handle user online status when he/she close the browser?

后端 未结 5 971
自闭症患者
自闭症患者 2021-01-06 01:47

I am having table to track user online status by setting \'is_online\' field to 1. Now User get logged in the site and shut down his/her system or power down at that time he

5条回答
  •  被撕碎了的回忆
    2021-01-06 02:06

    Store an time-since-last-activity. When it's been longer then a specified time - treat as if offline. You should replace the is_online with an DateTime field, and update it every time the logged in user visits the website.

    On the place you want to select all online users, instead of :

    SELECT * FROM users WHERE is_online = 1
    

    You could use:

    SELECT * FROM users WHERE is_online >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)
    

提交回复
热议问题