Find jobs - Internet Advertising - Debt Consolidation - Wordpress Themes - WoW Gold

PDA

View Full Version : users logged in script


jquilno
Aug 9th 2006, 2:47 pm
i have a startup website, BigRedNumber.com, and i use php with a mysql backend to store information.

my question is, how can i create a "users logged in now" script? i want to have the "users logged in now" part of the site dynamic, instead of having to purge the user login cache (login information is stored as a 1 or 0 in user database)?

right now, when a user logs in, the login field on his database entry becomes 1, but if he doesnt log out by clicking "logout" (i.e. he closes the browser window) he remains "logged in." i only want to show people who are logged in (and clicking) at the time the page is loaded.

thnx
j.

webviz
Aug 9th 2006, 9:33 pm
<?php

// ... init classes and whatnot...

if($user->logged != true)
{
$display->tpl('login_you_idiot');
}

// ... once the idiot logs in..

$db->query("UPDATE `status` SET `logged` = '1' WHERE `id = '{$user->id}'");

// where did $user->id come from? once the user logged in set the new values

// ...

?>






What you are asking for requires a full working member system thing

casper
Aug 10th 2006, 6:51 am
I would set a date/time combination in my DB rather than adding a 'logged in boolean' like webviz suggested.

If the user would log on a boolean login system but would not log out properly, the user could be 'active' forever, unless the system would actively scan the userlist, which is a waste of resources.

When setting a date, you could use a simple query like;


SELECT users FROM table WHERE logindate > 01-01-2006 AND logintime > 10:00:00 sprt by users desc;


And when you have stored a date/time combination in your db you can also add a welcome message like;


Welcome user, your last login was on xx:xx, xx-xx-xxxx!