Cookies.. Serialize/Unserialize..

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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("searchdata", serialize($searchdata), time()+3600,

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.

Re: Cookies.. Serialize/Unserialize..

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

$searchdata = unserialize(stripcslashes($_COOKIE['searchdata']));

Re: Cookies.. Serialize/Unserialize..

onefastmustang wrote:
Quoted text here. Click to load it

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($searchdata);
$searchdata = unserialize($s);


Site Timeline