Forum Moderators: coopster

Message Too Old, No Replies

Display list of logged in users

how to

         

d40sithui

5:11 pm on Jan 16, 2007 (gmt 0)

10+ Year Member



Greetings all,
I'm new to this forum and fairly new to php as well. I'm making a small website that includes a user login/logout feature. Its a friendly site and isn't anything fancy. What I'm working on now is to display a list of all the users that are currently logged in the website. The system I'm using now is basically a table ("current_users") that contains all the usernames of users that have successfully logged in. The table would fill as users logged in and empty as users log out. The problem is what if the user never clicks "logout" (and thus never executing the script that removes that user from the table), but simply closes the browser? The table would then never have a chance to remove that user from an "logged in" status... Does anyone know a better way to implement this? Please RE. Thanks,

-khanh

jatar_k

7:00 pm on Jan 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld d40sithui,

most users probably won't logout so what you need is a script that goes through and cleans up anything that is old.

This way you can just query that database for active users.

Another you may want is to update the time in the current_users table eveytime a user hits a new page. This keeps the users that are active, well, active.

your cleanup script can then delete anything in the table that has a time over 30 minutes, say, though it could be any amount you like. Just don't make it too short, give people time to read.

d40sithui

12:22 am on Jan 18, 2007 (gmt 0)

10+ Year Member



thanks for the reply. I will try what you say.

-khanh