Which users are logged in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

Which users are logged in

Post by thesimon »

Hi,

I have a few project where users log in to a secure area, this is just a basic login where the password and username is checked against what is in the database.

I would like other users to be able to see who else is online. How is it possible to know which users from the users table in the database are currently logged in?

Thanks,
Simon
Last edited by thesimon on Tue Apr 12, 2005 4:50 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Have a column in your database.

ENUM columns type, with values 0 or 1 for example.

If logged in set it to 1, otherwise set it to 0.

The just use MySQL's COUNT() function to get all the records where logged_in = '1'.

That should do it ;-)
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

you might want to consider who is online in a interval of time.
Some users might actually leave your website without logging out and come back in about a month; thus, they can't be logged in from the day they left until a month later :D
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

Post by thesimon »

thanks d11wtq, however as hongo said some of the users may fail to logout, thus the record wont change back, are any ideas to find out whos sessions are still running.thanks,
Simon
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

update their activity in a log somewhere and when that last act is sufficient amount of time say 5 mins. old then logout the user. this approach is pretty much used all the time.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Look at article Who is online
Post Reply