Im using wordpress
and I set cookies on a purpose which works perfectly on Chrome and other browsers, but not in Firefox, $_COOKIE
is empty when I print it in firefox, but contains cookies actually, the same code prints the cookies on other browsers, and of course cookies are visible in Firefox firebug, but not on $_COOKIE
.
can some one tell me how to access them? what is restricting? how to solve it?
My code goes this way
if(isset($_GET['attr'])){
$inTwoMonths = 60 * 60 * 24 * 60 + time();
$attr = $_GET['attr'];
setcookie('attr', $attr , $inTwoMonths,'/');
print_r($_COOKIE);
}
setcookie() only prepares a Cookie header for the response but it will not actually set the value in $_COOKIE. $_COOKIE will have the new value after the next request when it receives the updated cookie data from the client. See http://php.net/setcookie . In your code, you will have to do this:
in order for the value in the cookie to be available in the same request.