By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,492 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,492 IT Pros & Developers. It's quick & easy.

Cookies.. Serialize/Unserialize..

P: n/a
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,
'/',"somedomain.com")

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.

Oct 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Neva mind.. I figured it out.. I had to add stripslashes to this line.

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

Oct 17 '05 #2

P: n/a
onefastmustang wrote:
Neva mind.. I figured it out.. I had to add stripslashes to this line.

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


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);
print_r($searchdata);
JW

Oct 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.