[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


unserializing session data without creating new session

Posted on 2004-10-27
Medium Priority
Last Modified: 2006-11-17
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;
Question by:drew22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 48

Accepted Solution

hernst42 earned 2000 total points
ID: 12423555
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

Author Comment

ID: 12424458

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);
LVL 48

Expert Comment

ID: 12431107
are you using windows? On my linux-box where I tried it, it worked perfect (including an object)

Author Comment

ID: 12436138
I'll try it again.  Did you try it with session data containing arrays?
LVL 48

Expert Comment

ID: 12436507
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"

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question