note 16376 deleted from function.setcookie by john

From: Date: Sat, 30 Nov 2002 16:24:06 +0000
Subject: note 16376 deleted from function.setcookie by john
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-40160@lists.php.net to get a copy of this message
The docs for SetCookie point out one of the most common pitfalls is "Cookies will not become visible until the next loading of a page that the cookie should be visible for" .. To get a cookie to be viewable in the same page load as you call SetCookie(), just test for the cookies value and manually assign your value to the variable if the cookie is missing. This will allow your program to reference the variable the first load, then read the cookie for every subsequent call (until your cookie expires of course) ex: function ShowCookieHeader() global $myname; if (!(isset($myname))) { SetCookie("myname","Billy"); $myname = "Billy"; } return 1; } ShowCookieHeader(); print <<<EOF <html> <body> My name is $myname </body> </html> EOF;

« previous php.notes (#40160) next »