list of users that are logged on(sessions)

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
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

list of users that are logged on(sessions)

Post 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?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post 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!
User avatar
wmasterj
Forum Commoner
Posts: 40
Joined: Mon Aug 18, 2003 5:52 pm
Location: Stockholm, Sweden

Post 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!
User avatar
wmasterj
Forum Commoner
Posts: 40
Joined: Mon Aug 18, 2003 5:52 pm
Location: Stockholm, Sweden

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

Gen-ik,
Can yo post that script here?
I really want to get some ideas...
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
Post Reply