note 42468 added to function.session-decode
| From: | grangenospam at nospamclub-internet dot fr | Date: | Tue, 18 May 2004 08:29:35 +0000 |
| Subject: | note 42468 added to function.session-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69746@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.session-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42468
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42468&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42468&report=yes
Search -- http://master.php.net/manage/user-notes.php