note 21140 added to language.variables.scope

From: Date: Tue, 30 Apr 2002 17:14:57 +0000
Subject: note 21140 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-30020@lists.php.net to get a copy of this message
Seems as though when a cookie is saved and referenced as a variable of the same name as the cookie, that variable is NOT global. If you make a function ro read the value of the cookie, the cooke variable name must be declared as a global. example: function ReturnCookie() { $cookieName = "Test_Cookie"; global $$cookieName; if (isset($$cookieName)) { echo ("$cookieName is set"); $returnvalue = $$cookieName; } else { $newCookieValue = "Test Value"; setcookie("$cookieName","$newCookieValue", (time() + 3153600)); echo ("made a cookie:" . $newCookieValue ."<BR>"); $returnvalue = $newCookieValue; } echo ("the cookie that was set is now $returnvalue <BR>"); return $returnvalue; } -- http://www.php.net/manual/en/language.variables.scope.php http://master.php.net/manage/user-notes.php?action=edit+21140 http://master.php.net/manage/user-notes.php?action=delete+21140 http://master.php.net/manage/user-notes.php?action=reject+21140

« previous php.notes (#30020) next »