473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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("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
2 2962
Neva mind.. I figured it out.. I had to add stripslashes to this line.

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

Oct 17 '05 #2
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Sleeman | last post by:
Hi all, i just spent an hour rifling through code to find the cause of a problem only to find it's an oddity with serialization and recursive objects, so figured I'd post for the next person who...
2
by: Alexander Ross | last post by:
I want a cookie that can have about 5 values. I was told to do something like this: to set the cookie the first time: setcookie("questions",$_POST,time()+60*60*24,"/","",0); then to add valus...
8
by: John Smith | last post by:
Hi, I am using a custom Session Handler. session_set_save_handler is working well. But i want to read the data direct from the database. My problem: php don't uses the standard serialize...
2
by: Andrew | last post by:
Some have suggested that using serialize() and unserialize is faster than reading/writing an array to disk as a simple text file using $array = file('numbers.txt'); Can anyone justify this? ...
6
by: sandy | last post by:
With java servlets I can declare complex object-oriented class structures as session variables in a servlet. That means I can have a complex HTML form that submits iteratively back to the server...
1
by: Mark | last post by:
I'd like to take an instance of a class, and serialize it to a file on my computer. No security required on the file. Then, I'd like to be able to unserialize the file later and use the instance...
7
by: powellgg | last post by:
I've just taken over a PHP website and am converting it to ASP.NET (don't shoot!). I'm not a PHP guy so I'm doing a lot of searching for things that I aren't obvious, and I'm hoping I'll be able...
1
by: VooDoo | last post by:
Hi, I am using the serialize and unserialize to put and get data from mysql database. I think i could optimise the way i handle the data, but not really sure how. What is the best way to happend...
6
by: oooobs | last post by:
Hello i have deficulty to deal with cookies in PHP my website is http://kal.am cookies not working and when i tried to print session array i got the following strange output: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.