note 31464 added to function.setcookie
| From: | janhouse00 at hotpop dot com | Date: | Wed, 23 Apr 2003 00:43:52 +0000 |
| Subject: | note 31464 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46960@lists.php.net to get a copy of this message | ||
Bear in mind if you tried to store MULTIPLE STRING VALUE IN ONE COOKIE, you have to employ
addslashes prior to serializing them(sound odd but I just dunno why, myself has been spending tons
of time to figure it out).See the following scripts:
//makecookie.php
<?
$array[0]=addslashes("a");//it doesn't work if you remove the addslashes()
$array[1]=addslashes("b");
$array[2]=addslashes("c");
//print_r($array)
$s=serialize($array);
setcookie("cookies",$s,time()+86400);
?>
//test.php
<?
if(isset($cookies)){
$array=unserialize(stripslashes($cookies));
foreach($array as $i=>$cookie){
print"<br>$i => $cookie";
}
}
?>
--
http://www.php.net/manual/en/function.setcookie.php
http://master.php.net/manage/user-notes.php?action=edit+31464
http://master.php.net/manage/user-notes.php?action=delete+31464
http://master.php.net/manage/user-notes.php?action=reject+31464