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
Checking who's online
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Checking who's online
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.
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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
tehhparadox
- Forum Newbie
- Posts: 18
- Joined: Thu Oct 01, 2009 11:55 am
Re: Checking who's online
would the stored sessions in the db timeout automatically?
Re: Checking who's online
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.
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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.