Read all session data from session storage file in php.

@mit $ingh. July 13, 2016 Comments

If you want to decode session data, use session_decode (see the manual). unserialize only decodes single variables, not session data.

You can do something like:

//get session storage path
$dir = ini_get("session.save_path");

//get all session files
$sessFiles = preg_grep("/^sess_/", scandir($dir));

//get all session data by looping the files.
foreach ($sessFiles as $key => $value) {
    $contents = file_get_contents($dir . $value);
    echo '<hr><pre>';


If you want to keep session data in another variable you can do like below.

// if session is not started

// store our current session
$my_sess = $_SESSION;

// decode $contents (the encoded session data, either from a file or database). Remember, decoded data is put directly into $_SESSION
$data = $_SESSION;


// restore our own session
$_SESSION = $my_sess;


  • PHP
  • session