note 16376 added to function.setcookie

From: Date: Fri, 26 Oct 2001 19:21:50 +0000
Subject: note 16376 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-19488@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; -- http://www.php.net/manual/en/function.setcookie.php http://master.php.net/manage/user-notes.php?action=edit+16376 http://master.php.net/manage/user-notes.php?action=delete+16376 http://master.php.net/manage/user-notes.php?action=reject+16376

« previous php.notes (#19488) next »