note 21141 added to function.setcookie
| From: | lucifersam at dotnuxx dot net | Date: | Tue, 30 Apr 2002 17:16:08 +0000 |
| Subject: | note 21141 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30021@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;
}
--
http://www.php.net/manual/en/function.setcookie.php
http://master.php.net/manage/user-notes.php?action=edit+21141
http://master.php.net/manage/user-notes.php?action=delete+21141
http://master.php.net/manage/user-notes.php?action=reject+21141