I\'m trying to access a cookie\'s value (using $_COOKIE
) immediately after calling the setcookie()
function in PHP. When I do so, $_COOKIE[\
$_COOKIE
is set when the page loads, due to the stateless nature of the web. If you want immediate access, you can set $_COOKIE['uname']
yourself or use an intermediate variable.
For example:
if (isset($_COOKIE['uname'])) {
// get data from cookie for local use
$uname = $_COOKIE['uname'];
}
else {
// set cookie, local $uname already set
setcookie('uname', $uname, time() + 1800);
}