mattbrown Posted May 22, 2006 Share Posted May 22, 2006 Hi,I've recently been testing out some stuff for a website I plan to build and would like to include what sounds like a simple feature but I can't seem to find any info about how other poeple have gone about this.Basically on the site there is a login system using PHP/MySQL all pretty standard stuff really but what i would like to do is have a list of currently logged in users and their usernames on the front page, similar to the bottom of the front page of most PHPBB forums.At first the solution seems simple, I though I'd just make a value change in the users row of the database when they log in then have it change back when they log out but as we all know just about everyone just closes the browser window thus leaving the database value set to logged in.The only other idea I've had but not tested yet is to have the time the user logged in stored to the database then every time they load a page have this field updated. This would make it possible to for some kind of sql query to only return the username in rows that have a timestame no older than 5 minutes of the current time but this seems very messy and surely would result in way to many database connections.So please if anybody has any ideas or information please let me knowMany ThanksMatt Quote Link to comment https://forums.phpfreaks.com/topic/10212-logged-in-users-list/ Share on other sites More sharing options...
.josh Posted May 22, 2006 Share Posted May 22, 2006 [code]The only other idea I've had but not tested yet is to have the time the user logged in stored to the database then every time they load a page have this field updated. This would make it possible to for some kind of sql query to only return the username in rows that have a timestame no older than 5 minutes of the current time but this seems very messy and surely would result in way to many database connections.[/code]that's pretty much exactly what forums do. They have a "last logged in" type of column and everytime the user accesses a new page, the timestamp changes to the current timestamp. Then the "Active users in the past x minutes" is based on a query for all users within the x minutes time range. unfortunately, with php being a server side language, that's about the best you're gonna get. Now, you could probably find a better solution using Ajax... and when I say "better," what I really mean is more accurate. But you are going to have to update the database somehow, in order for the page to show data based on everybody. The database serves as the central hub for everybody. There's just no way around that, unless you want to script it using .txt files or or something.... Quote Link to comment https://forums.phpfreaks.com/topic/10212-logged-in-users-list/#findComment-38063 Share on other sites More sharing options...
mattbrown Posted May 22, 2006 Author Share Posted May 22, 2006 Excellent Thanks [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] I'll give it a go tomorrow Quote Link to comment https://forums.phpfreaks.com/topic/10212-logged-in-users-list/#findComment-38067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.