I am working on a chat application in PHP. Here I am saving one login session_id in to my database. When a user logout I am setting this session_id to null. So by this way I am getting who other users are logged in. My script is checking for every 5 second for this session_id & respective message if chat box is open.
Now suppose user has closed the browser itself, then how to remove him from chat-box active user list ?
When we are closing the browser, the session will get expire. Is there any thing I can trace which are all session_id‘s currently active on a server for a particular website ?
Or Is there any way to Track all active users for chat application in PHP ? I am not getting what parameter I am missing here.
Please help me.
Exactly how Lucas said. Have a timestamp field calld e.g. “last_seen” and update it via AJAX in every 5 seconds (what you are doing right now anyway). Then you may think about all users that this query return as being active:
and all others are offline (closed their browser or sth).
In the above query we assume that if user has not been seen for 30 seconds – he is offline. This value can be lower, but must be above 5 seconds (your refresh interval) because there always can be some delays in updating last_seen column.