Page 1 of 1

list of users that are logged on(sessions)

Posted: Tue Oct 07, 2003 10:49 am
by yaron
Hello all,
I create a session variable (user name) for every user that is logging on to my system.
What I want to do is
1. To write a script that lists all of the users that are logging on
($_SESSION['user'])
I'm guessing that I can loop it somehow but I'm not sure how.

2. to destroy the session when the user is logged out.

any ideas?

Posted: Tue Oct 07, 2003 10:56 am
by Nay
Use an array, make an array called online and have the usernames added when they log in and unset them when they log out.

-Nay

Posted: Tue Oct 07, 2003 10:57 am
by yaron
Is there a way to knoe where a user logged out?
I want to remove his session when he closes all system's windows!

Posted: Tue Oct 07, 2003 3:06 pm
by wmasterj
you could also store the users logged on in a field in you database...seems like a good idea to me. ;)

I think the only way to unset a session is to let the user click a "log out" button, the just set the "time of death" for the session to 0 = killed :D :)

Hope it works!

Posted: Tue Oct 07, 2003 3:09 pm
by wmasterj
oh yea and for the "last page" thing, if you update the sessioncookie with the name of the page the users is visiting. So every time he/she enters a new page the sessioncookie is updated with new info. :?:

Good luck :lol:

Posted: Wed Oct 08, 2003 4:25 am
by twigletmac
You can also have a 'users active over the last 10 minutes' type thing, by checking the times they logged in - if someone hasn't done anything for a few hours you can assume that they have finished their session and log them out.

Mac

Posted: Wed Oct 08, 2003 4:25 pm
by Gen-ik
Hi. Personally I dump the name of the user who has logged-in into a database along with the current time. When they are logged-in their record in the database (the time) gets updated.

I have a script that runs every ten minutes (automatically) which checks the times in the database. If someone has been unactive for more than ten minutes (or 15 max) then the script removes the users 'session' from the database and presumes the user has left the site.

Posted: Thu Oct 09, 2003 10:24 am
by yaron
Gen-ik,
Can yo post that script here?
I really want to get some ideas...

Posted: Thu Oct 09, 2003 10:25 am
by JAM

Posted: Thu Oct 09, 2003 2:13 pm
by Gen-ik
yaron wrote:Gen-ik,
Can yo post that script here?
I really want to get some ideas...
As far as the 'automatic' PHP code goes (the stuff that runs every 10 minutes or so) I'm not sure how that works as it's something the server has set-up. Basically I put PHP code into a page on the server and it gets run every 10 minutes, maybe someone else knows how to set this up?

The theory behind the "if the user is logged in update a database with the current time" is pretty simple if you know how to use MySQL or MSQL and SESSIONS.

If you really get stuck though drop me an email and I'll send some stuff over to you.