I have created a chat system using php and ajax. When a user logs into this chat system, in table is_online field status is updated to 1. I am using this field to list current online members.
I have to update status to 0 if the user closes all the tabs of my website without pressing logout.
How can I do it?
Really bad method.
Make a table
online_userswith fieldsnameandtimeout.Store user’s name (or ID, or any other identification) and current timestamp + 5 minutes (or different threshold, you decide).
When displaying online users, select all users from that table where
timeoutis BIGGER than current timestamp.Example:
And set up a CRON that will clean the table once a day.
And don’t forget to update
timeout.