Cookies doesnt showup in Firefox with $_COOKIE but visible in firebug and works on other Browsers

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);
}

Related posts

Leave a Reply

1 comment

  1. 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:

    setcookie('attr', $attr , $inTwoMonths,'/');
    $_COOKIE['attr'] = $attr;
    

    in order for the value in the cookie to be available in the same request.