Page 1 of 1

Checking who's online

Posted: Fri Feb 19, 2010 11:07 am
by tehhparadox
Hi guys

I'm making a chat application with flash and php, and I would like to know how you see if someone's online.

I have a login which registered users can log into my application, and this is done with a MySQL database. I know website update a 'logged_in' column to true or something similar when a user is logged in, but using that method, how do you check if the person is offline? I suppose you can update the database when a 'logout' button is clicked, but some users may not do that, and close the window instead.

Any help would be appreciated.

Thanks

Re: Checking who's online

Posted: Fri Feb 19, 2010 11:23 am
by AbraCadaver
Normally I think that you would setup your app to store sessions in the database. You would add a username or userid column to that table. Then when you wanted to see whose online, you would just query the sessions table and return the usernames. This however would depend upon how long the sessions stay active.

Instead, you might look at an AJAX call that updates a DB table with the username and the time every minute. Then you can query the db for the users with a time that is within 1 minute of the current time.

Re: Checking who's online

Posted: Mon Mar 15, 2010 4:24 pm
by tehhparadox
would the stored sessions in the db timeout automatically?

Re: Checking who's online

Posted: Mon Mar 15, 2010 5:08 pm
by s.dot
Generally you use a timestamp for this, and query for who has been active within the last X minutes to determine who's online. You update the timestamp when they have activity.

If they may be idle for a period of time but still considered "logged in" (eg: just reading the chat instead of chatting), then an AJAX call to update the timestamp every X minutes or so may be necessary.