hi to all,
i am using array into cookie, code is bellow
$data=array("apple", "banana", "orange", "mango");
$final=serialize($data);
$exp=time()+3600;
setcookie('fav_names', $final, $exp);
foreach(unserialize($_COOKIE['fav_names']) as $k => $v)
echo $k . '----' . $v ;
This is the Error:
Warning: Invalid argument supplied for foreach() in D:\VertrigoServ\www\names-meanings\helper.php on line 6
using array into cookie
Moderator: General Moderators
-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: using array into cookie
I could be mistaken but I don't think $_COOKIE[] will contain what you put in setcookie() until the next page load. Again, I may be mistaken but I think $_COOKIE[] gets populated when the php script starts up, setcookie() sends header information, and on subsequent page loads, the browser sends those cookies back to the server.
Shawn
Shawn