tags:

views:

218

answers:

3

I would like to get session list from the localhost.So, I wrote

session_start();
print_r($_SESSION);

currently access person is two.one is from another PC and the last one is hosted pc.But the on shown only hosted pc session.Actually I would like to get all session user list.

+2  A: 

Sessions are isolated from each other. One user's session doesn't have access to another user's session. The variable $_SESSION references only the current user's session.

I don't think there's a way to access a different user's session other than finding out where the session files are physically stored on disk and parsing them by hand. NOTE THAT THIS IS NOT USUALLY SOMETHING YOU WANT TO DO.

deceze
how to make to get all session ?someway ?
+1  A: 

I'm not sure what you are asking, but I think you are looking to get another session from another user. If this is the case, then I wouldn't recommend it and it's not really possible. Sessions are individual to each browser session (unless specified otherwise through cookies).

If you are asking to retrieve your sessions from your own user from another computer, then again, the default session behaviour is not really made to do this. You would need to implement your own session manager that probably uses a database and keeps track of which session is for which user (user id probably) so it can load it on another computer. I wouldn't recommend this either because you're getting into another whole ball of wax, per say.

If you are trying to keep track of data across user logins and computers, I would recommend using a user settings table. Here you can track the settings that the user has and load them each session or even each page load without having to modify the session handler.

If from your title you are wanting to get a list of currently active sessions, then simply record the last hit time of each user in a table and display that data, having a set time when you consider the session inactive.

Darryl Hein
+1  A: 

This can easily be done with the following code:

<?php

$sessions = array();

$path = realpath(session_save_path());
$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $file)
{
    $sessions[$file] = unserialize(file_get_contents($path . '/' . $file));
}

echo '<pre>';
print_r($sessions);
echo '</pre>';

?>

Make sure you understand the risks in doing (or allowing) this.

Alix Axel