...

View Full Version : Using arrays in cookies?



cyphix
06-28-2005, 06:54 PM
Is there a way to successfully use arrays in cookies? Like I wanna add to the cookie but it doesn't seem to work..

Tried doing this but it doesn't seem to work..



setcookie("cookiename[]", somedata, time() + 15768000, '/', '.domain.com');


Any ideas?? :confused:

Thanks!

Kurashu
06-28-2005, 07:37 PM
Serialize the array.

http://www.php.net/serialize

cyphix
06-28-2005, 07:44 PM
Could u give me an example? I'm not sure I'm understanding it correctly. :o

Kurashu
06-28-2005, 08:45 PM
$array = array('one', 'two' 'tacos' => 'three');
$somedata = serialize($array);
setcookie("cookiename", $somedata, time() + 15768000, '/', '.domain.com');

cyphix
06-28-2005, 09:23 PM
Hmm.... but how would you use that to add to an exisiting cookie?

Kurashu
06-29-2005, 12:43 AM
I'm not sure, I don't work with cookies enough to tell you.

cyphix
06-29-2005, 12:48 AM
Oh ok... thx 4 the help anyways! :thumbsup:

marek_mar
06-29-2005, 12:58 AM
You should just watch out for one thing. The serialized arrays carry their types of values unlike _POST/_GET (where everything is a string) so you might want to check if the types are correct.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum