Page 1 of 1

How to check who is currently logged in?

Posted: Thu Apr 10, 2008 10:06 pm
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???

Re: How to check who is currently logged in?

Posted: Fri Apr 11, 2008 3:06 am
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.