Can’t set PHP cookie on the same page

See the manual on setcookie() (emphasis mine):

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays. Note, superglobals such as $_COOKIE became available in PHP 4.1.0. Cookie values also exist in $_REQUEST

Here is a workaround suggestion. It’s imperfect because it can’t guarantee the cookie actually gets set, but might do in your case.

Leave a Comment