tags:

views:

84

answers:

3

How can I get a list of all active PHP sessions on a server and access them from within one user's instance?

The motivating case is displaying a list of all currently active users on the site, where usernames are stored in each user's PHP session.

Note: I know that I can create my own state via a database (or even the filesystem), but I'm looking for a way to utilize the built-in PHP session mechanisms.

A: 

The sessions are stored as files in your temporary session directory. You should be able to locate this in the php.ini (or using phpinfo() ). Those are all the sessions. You should be able to check the file time to see if they are active within the last x minutes.

Brad F Jacobs
+2  A: 

this thread should be what you are looking for.

pixeline
Definitely a way to access the sessions, but as @Artefacto mentions its a hack and doesn't really "utilize the built-in PHP session mechanisms".
Greg Harman
+2  A: 

Seeing the responses, though it's possible, it doesn't mean you should do it. The format in which the sessions are stored is not documented and may change at any time (even between minor versions).

The correct way to do this is to implement your own session handler. It's not that hard, really.

Artefacto