PLEASE HELP - Update database on browser close??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ewannnn
Forum Newbie
Posts: 13
Joined: Thu Nov 04, 2010 9:46 am

Re: PLEASE HELP - Update database on browser close??

Post by ewannnn »

Sorry I shuold be more specific, it does not update the database, it just does nothing.
What i want is for the following query to be executed if the user closes the browser:
mysql_query("UPDATE users SET status='Offline' where alias='".($_SESSION['alias'])."';");
The user status is online even if the browser is closed and reopened, it does not execute the query. What i want is to update the database on browser close.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PLEASE HELP - Update database on browser close??

Post by s.dot »

A better way (and very common way) to determine users online is to use the time they were last active. Update a timestamp when a user performs an action.

If a user hasn't performed an action with the last X (say 5) minutes, then they are considered to be offline.

That is how this board does it.
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.
Post Reply