I have a field in my db called "loggedin" which is a simple 1 or 0 depending on whether the player is logged in or not. The login code sets it to 1 and it remains at that value until the player logs out.
I also have a logout page which then sets this to 0 and destroys the session, but what happens when the player closes the browser window without logging out?
How do I execute the logout code and set this field to 0 in that instance?
Question about tracking logins/logouts
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Question about tracking logins/logouts
many of these are set on timers. Like crons. They run every 15 minutes and check last query VS current time. If current time - last query = to long it sets the value to 0. I know this may not be what you are looking for but its the best I got right now but I will look into this.
Re: Question about tracking logins/logouts
To keep track if a player is online or offline there is often no need for crons.
Simpy save the time when the player last did something in the database. Then just check if that was in the last X minutes. (X = how long they should be allowed to be idle without being logged out).
Simpy save the time when the player last did something in the database. Then just check if that was in the last X minutes. (X = how long they should be allowed to be idle without being logged out).
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
Re: Question about tracking logins/logouts
But how would you check that?
If they aren't using their browser anymore, there are no pages being loaded for the check to be made. It's like this has to be run on the server somehow?
If they aren't using their browser anymore, there are no pages being loaded for the check to be made. It's like this has to be run on the server somehow?
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Question about tracking logins/logouts
that is where the cron comes in...
Re: Question about tracking logins/logouts
Guess I need to review that tutorial on crons then 
Re: Question about tracking logins/logouts
You don't check, unless someone wants to know if they are online or offline.OldRod wrote:But how would you check that?
If they aren't using their browser anymore, there are no pages being loaded for the check to be made. It's like this has to be run on the server somehow?
In database field 'last-action' you save for example '2009-12-31 12:30'. And then if someone wants to see if he is offline or online you just check how long since his last action, and it was more than lets say 15minutes then it says offline otherwise online.
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
Re: Question about tracking logins/logouts
What I'm trying to do is keep someone from logging in twice from two different browsers at the same time with the same username.
I had planned to have a "logged in" field set to 1 if they were logged in, and and 0 if they logged out, then check that field on subsequent login attempts. But as I was testing it, I ran into the problem of not logging out on one browser, so I got the "already logged in" message when I really wasn't.
Is there a different or better way to do this?
I had planned to have a "logged in" field set to 1 if they were logged in, and and 0 if they logged out, then check that field on subsequent login attempts. But as I was testing it, I ran into the problem of not logging out on one browser, so I got the "already logged in" message when I really wasn't.
Is there a different or better way to do this?
Re: Question about tracking logins/logouts
Erm.. put in the timestamp they logged in. Using the time() function. This will give you the ammount of seconds that have passed since January 1st 1970. :O. Okay, not important though. Then check to see if 60*the ammount of minutes you let them be inactive for before declaring the are offline + the last active field in the database is greater than time().
In the hope this wont be asked again I'll post it now.
Updateing the table with the user information
Getting an array of the users online in the last five minutes
In the hope this wont be asked again I'll post it now.
Updateing the table with the user information
Code: Select all
<?php
mysql_query("UPDATE `usershit` SET `last_active` = '". time() ."' WHERE `id` = '$theUsersId'");
?>
Code: Select all
<?php
$userQuery = mysql_query("SELECT * FROM `usershit` WHERE `last_active`+300 > ". time() .""); // 5 mintues I think?
while( $userArray = mysql_fetch_assoc($userQuery) )
{
echo $userArray['username']."<br />\n";
}
?>
Fighting for peace is declaring war on war. If you want peace be peaceful.