lizam
|
| Posted: 02/24/2005, 5:09 PM |
|
I have a column named is_online in my users table to indicate whether the user is currently logged in into the system.
Below is the code that I add into Common.php:
function CCLoginUser($user, $password) {
...
...
...
$SQL="UPDATE users SET is_online=1 WHERE user_id='".CCGetSession("UserID")."'";
$db->query($SQL);
$db->close();
return $Result;
}
function CCLogoutUser()
{
$SQL="UPDATE users SET is_online=0 WHERE user_id='".CCGetSession("UserID")."'";
$db->query($SQL);
$db->close();
...
...
...
}
Everything works fine. The column is updated accordingly. The only issue is if the user does not properly come out from the system i.e. by closing the browser instead of clicking the logout button which call the function CCLogoutUser. In this case, the column is not updated.
Any ideas how to deal with this?
Thanks for any feedback.
|
|
|
 |
wronco
Posts: 15
|
| Posted: 02/28/2005, 2:03 PM |
|
You could add a field 'expires_at', which would specify a time after which you would assume that is_online was 0.
You'd have to update that field with every page refresh, so that if someone were logged in, they wouldn't get kicked off after X minutes of browsing.
Something like:
function CC_refresh_user() {
"UPDATE users set expires_at=now()+ 10 minutes where user_id=CCGetSession(UserID)"
}
at the top of each restricted page.
Then, instead of always checking the field "is_online", you'd also have to check "expires_at" to see whether the value in "is_online" is still valid.
Maybe more trouble than it works, but you could hack it together.
Will
_________________
http://www.willronco.com |
 |
 |
|