How to check who is currently 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
Yourchild
Forum Newbie
Posts: 16
Joined: Mon Jul 30, 2007 3:04 pm

How to check who is currently logged in?

Post by Yourchild »

How do I go about checking to see who is logged onto my website?

if(isset($_SESSION['userID'])){
display content for logged in user
}
else{
display content for non-logged in user
}

this will tell me what to echo depending if the user is logged in or not.

But how do I check every user account in the db and determine who is currently logged in?

If a user logs into the site, I can set a loggedIn field in the user's table to 'true'.


Then when the user clicks the log out button, I can easily set that field to false...but if the user closes the browser or navigates to another site, I am without a clue on how to update the db...

Any ideas???
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: How to check who is currently logged in?

Post by aceconcepts »

I think in this case what you would have to do is detect whether the browser window is attempting to close (probably by using Javascript) and deal with it from there.

Have a look on the web for such Javascript procedures.
Post Reply