note 31499 added to function.setcookie

From: Date: Thu, 24 Apr 2003 02:37:55 +0000
Subject: note 31499 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-47015@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). This code (from above): <? $array[0]=addslashes("a");//it doesn't work if you remove the addslashes() $array[1]=addslashes("b"); $array[2]=addslashes("c"); echo serialize($array); ?> Returns: a:3:{i:0;s:1:"a";i:1;s:1:"b";i:2;s:1:"c";} ... and so does the same code without addslashes(): <? $array[0]="a"; $array[1]="b"; $array[2]="c"; echo serialize($array); ?> Returns: a:3:{i:0;s:1:"a";i:1;s:1:"b";i:2;s:1:"c";} Possibly you need addslashes() if your values contain ' or " but I never needed it (if "magic quotes" is on). In such a case you could just use addslashes() on the serialized string. -- http://www.php.net/manual/en/function.setcookie.php http://master.php.net/manage/user-notes.php?action=edit+31499 http://master.php.net/manage/user-notes.php?action=delete+31499 http://master.php.net/manage/user-notes.php?action=reject+31499

« previous php.notes (#47015) next »