Jump to content


Photo

Logged In Users List


  • Please log in to reply
2 replies to this topic

#1 mattbrown

mattbrown
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 May 2006 - 08:20 PM

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 08:59 PM

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.

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....
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 mattbrown

mattbrown
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 May 2006 - 09:18 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users