Cookies.. Serialize/Unserialize..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • onefastmustang

    #1

    Cookies.. Serialize/Unserialize..

    I have a cookie that I serialize and set as follows..

    $searchdata[state] = $state;
    $searchdata[country] = $country;
    $searchdata[radius] = $radius;
    $searchdata[radius_zip] = $radius_zip;
    if ($_GET[roles]){
    foreach ($_GET[roles] as $value){
    $searchdata[r. $value] = 1;
    }
    }

    setcookie("sear chdata", serialize($sear chdata), time()+3600,
    '/',"somedomain.c om")

    Whats the best method to unserialize and make it all usable data
    again?? I tried various methods but I can't seem to access the data.

  • onefastmustang

    #2
    Re: Cookies.. Serialize/Unserialize..

    Neva mind.. I figured it out.. I had to add stripslashes to this line.

    $searchdata = unserialize(str ipcslashes($_CO OKIE['searchdata']));

    Comment

    • Janwillem Borleffs

      #3
      Re: Cookies.. Serialize/Unserialize..

      onefastmustang wrote:[color=blue]
      > Neva mind.. I figured it out.. I had to add stripslashes to this line.
      >
      > $searchdata = unserialize(str ipcslashes($_CO OKIE['searchdata']));
      >[/color]

      If you would define the array before assigning values to and serializing it,
      you will see that it also works without stripcslashes() :

      $searchdata = array();
      $searchdata['state'] = 'Foo';
      $searchdata['country'] = 'Bar';
      $searchdata['radius'] = 100;
      $searchdata['radius_zip'] = 1000;
      $s = serialize($sear chdata);
      $searchdata = unserialize($s) ;
      print_r($search data);


      JW



      Comment

      Working...