Jump to content

Archived

This topic is now archived and is closed to further replies.

mattbrown

Logged In Users List

Recommended Posts

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 know


Many Thanks
Matt

Share this post


Link to post
Share on other sites
[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....

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.