note 41637 added to function.setcookie

From: Date: Sat, 17 Apr 2004 19:17:54 +0000
Subject: note 41637 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-68258@lists.php.net to get a copy of this message
I just found this in a hard way: Do not add space(s) inside the brackets [ ] when setting up an array cookie or you will have a problem retrieving the value. // good setcookie( "cookie_name[$id]", $cookie_value ); // bad setcookie( "cookie_name[ $id ]", $cookie_value ); When you use foreach ($_COOKIE['cookie_name'] as $name => $value) { echo "$name : $value <br />\n"; } to get the value, both good and bad methods will return the value with no problem. But when you use $value = $cookie_name[ $id ]; only the good method (with no space) works. Weird eh? ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41637 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41637&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41637&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68258) next »