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.
<?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
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; And when you have stored a date/time combination in your db you can also add a welcome message like;