Re: setcookie issue

From: Date: Sun, 27 Mar 2005 18:29:30 +0000
Subject: Re: setcookie issue
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-211672@lists.php.net to get a copy of this message
John Hinton wrote:
The thing is, on the next action switch print_r($_COOKIE); returns empty until I refresh the browser. So, thusly, the second page load brings in the cookies.
$_COOKIES is a convenient array that contains the contents of the Cookie header, nicely parsed. Whenever you set a cookie, you're really adding a Set-Cookie header to the response. Thus, the browser has no way of knowing your intent until it receives the response. This data won't be in $_COOKIES until a subsequent request is made in which that cookie is included in the Cookie request header. This chapter of HTTP Developer's Handbook explains cookies: http://shiflett.org/books/http-developers-handbook/chapters/11 See Figure 11.3 for an illustration of the exchange I just described. Hope that helps. Chris -- Chris Shiflett Brain Bulb, The PHP Consultancy http://brainbulb.com/

« previous php.general (#211672) next »