unserializing session data without creating new session

I'm trying to create a session browser that will allow me to inspect sessions in my session table.
I found this function somewhere to convert  session data to an array, but it only works with variables in the session, not arrays in the session

function sess_string_to_array($sd)
      $sess_array = array();
      $vars = preg_split('/[;}]/', $sd);

      for ($i=0; $i < sizeof($vars); $i++)
            $parts = explode('|', $vars[$i]);
            $key = $parts[0];
            $val = unserialize($parts[1].";");

            $sess_array[$key] = $val;
      return $sess_array;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this one:
function unserializesession($data) {
   $vars=preg_split('/([a-z,A-Z]+)\|/',$data,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
   for($i=0; $vars[$i]; $i++) {
   return $result;

Taken from http://de3.php.net/manual/en/function.session-decode.php#46114

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drew22Author Commented:

Didn't work for me.  
I might try http://www.evilwalrus.com/viewcode.php?codeEx=553 , but it is huge, and I can always manually extract arrays via this hard-coded:

      $ar_name = 'completed|'

       $p1 = strpos($sess_data, $ar_name');
      $p2 = strpos($sess_data, ';}',$p1);
      $s= substr($sess_data,$p1+strlen($ar_name),$p2-$p1+2);  
        $completed = unserialize($s);
are you using windows? On my linux-box where I tried it, it worked perfect (including an object)
drew22Author Commented:
I'll try it again.  Did you try it with session data containing arrays?
Yes, I tried it with an objects that contained an array and additional array:


var_dump(of that function returned:
array(4) {
  string(7) "Orc_RIP"
  string(15) "1098978095.8022"
  array(3) {
    array(1) {
      array(1) {
        string(90) "./inputdatamulti.php?cmd=edit&class=Collection&SESSIONID=1098978095.8022&Collection=100109"
    array(2) {
      array(1) {
        array(2) {
          string(8) "03010103"
          string(10) "0301010301"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.