note 44837 added to function.unserialize

From: Date: Tue, 17 Aug 2004 18:38:22 +0000
Subject: note 44837 added to function.unserialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-79918@lists.php.net to get a copy of this message
I recently found myself in need of unserializing PHP session data (stored in a database) that had expired but was not yet deleted i.e. I needed to get at the contents of the session but was unable to use the usual PHP interface. The following function takes a string of serialized session data and returns an array of PHP values. The structure of the returned array is the same as the $_SESSION array if you were using the normal interface. I haven't tested this extensively but it did the job for me. <?php function unserialize_session_data( $serialized_string ) { $variables = array( ); $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); for( $i = 0; $i < count( $a ); $i = $i+2 ) { $variables[$a[$i]] = unserialize( $a[$i+1] ); } return( $variables ); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.unserialize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44837 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44837&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44837&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79918) next »