Accessing $_COOKIE immediately after setcookie()

The cookie isn’t set until the response is sent back to the client, and isn’t available in your PHP until the next request from the client after that.

However, when you set the cookie in your script, you can do:

setcookie('uname', $uname, time()+60*30);
$_COOKIE['uname'] = $uname;

Leave a Comment