Your lines:
setcookie(NAME_COOKIE, $username,time() + (86400),"/", $cookie_domain); print $_COOKIE[NAME_COOKIE];
What happens here is that you are setting a cookie, which means that the string * is added to the headers ready to be sent with your content.
think of it as a queue, and the queue goes to the browser only when you submit your content.
since your cookie is still in the queue, it was not actually set until the page was sent and you didn’t remember the page, and then, when you call, the browser will send the cookie information back to the browser, which, in turn, compiles the $_COOKIE array.
Think of it this way:
- SetCookie ();
- try
$_COOKIE - send content
- (BROWSER SETS COOKIE TO FILE)
- updates
- (BROWSER SENDS COOKIE INFO SERVER)
- php compiles
- ($ _ COOKIE LOADED FROM BROWSER DATA)
- try
$_COOKIE
Hope this helps.
source share