note 42468 deleted from function.session-decode by nlopess

From: Date: Tue, 18 May 2004 13:26:21 +0000
Subject: note 42468 deleted from function.session-decode by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-69763@lists.php.net to get a copy of this message
Note Submitter: grangenospam@nospamclub-internet.fr ---- Here's my attempt at providing a function to decode a session in an array. It's a bit dirty but it works with complex types such as arrays or objects. You'll need to adapt it if you use your own storage handlers or session_id(). <?php function decode_session($id) { // read session content // NOTE : only works when sessions are stored in files and session_id() was not used prior to saving the session $session_content = @file_get_contents(ini_get('session.save_path') . '/sess_' . $id); // return false if an error has occured if (false === $session_content) { return false; } // session_decode() only works if a session has been started @session_start(); // save current $_SESSION and empty it $_saved_SESSION = $_SESSION; $_SESSION = array(); // decode in $_SESSION session_decode($session_content); // save the result of session_decode() $result = $_SESSION; // restore current $_SESSION $_SESSION = $_saved_SESSION; return $result; } ?>

« previous php.notes (#69763) next »