note 61177 added to function.session-decode

From: Date: Fri, 27 Jan 2006 13:01:03 +0000
Subject: note 61177 added to function.session-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-102560@lists.php.net to get a copy of this message
Another solution for decoding session string to "$_SESSION"-like array: <?php // returns decoded string as arrays of variables // or false on error (when session_decode returns false) function DecodeSession($sess_string) { // save current session data // and flush $_SESSION array $old = $_SESSION; $_SESSION = array(); // try to decode passed string $ret = session_decode($sess_string); if (!$ret) { // if passed string is not session data, // retrieve saved (old) session data // and return false $_SESSION = array(); $_SESSION = $old; return false; } // save decoded session data to sess_array // and flush $_SESSION array $sess_array = $_SESSION; $_SESSION = array(); // restore old session data $_SESSION = $old; // return decoded session data return $sess_array; } ?> Example of use: <?php $sarr = DecodeSession($sess_str); print_r($sarr); ?> But I have not tested performance. ---- Server IP: 64.246.30.37 Probable Submitter: 62.168.125.219 (proxied: 10.16.5.21) ---- Manual Page -- http://www.php.net/manual/en/function.session-decode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61177 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61177&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61177&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102560) next »