Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/10212-logged-in-users-list/
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....
Link to comment
https://forums.phpfreaks.com/topic/10212-logged-in-users-list/#findComment-38063
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.