note 21141 deleted from function.setcookie by philip

From: Date: Tue, 16 Jul 2002 16:57:36 +0000
Subject: note 21141 deleted from function.setcookie by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-33150@lists.php.net to get a copy of this message
You need to declair the cookie as a global if you intend to use it within a function. 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; }

« previous php.notes (#33150) next »