Re: How to use multiple cookie statements

From: Date: Mon, 12 Jul 2004 19:53:36 +0000
Subject: Re: How to use multiple cookie statements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-190276@lists.php.net to get a copy of this message
Ronald "The Newbie" Allen wrote:
aHere is my code... <? setcookie("cookie[name]","$_POST['name']", time()+86400) setcookie ("cookie[email]","$_POST['email']", time()+86400) setcookie ("cookie[bgcolor]","$_POST['bgcolor']", time()+86400) setcookie ("cookie[tcolor]", "$_POST['tcolor']", time()+86400) ?> I have to use cookies, since I am taking a class and it dictates that we use cookies, but I can't email my instructor since she never responds. So how do I use a cookie to record multiple values? Help would be appreciative.a
As the standard says, 1 cookie = 1 value, no way to have more than one value in a cookie. But you can think about some workarounds, a quick example just to give you an idea: $cookie = implode(':', $array) Here you will have all values from the array in the cookie, and using : as a separator. To reverse the values: $values = explode(':', $cookie) and here you will have all values in the array $values, starting with index 0. Of course, in this way you can only set values, not the array keys. Look in the manual for implode() and explode() and see if is usefull for you. Regards, Jordi.

« previous php.general (#190276) next »