Search code examples
phpcookiesgoogle-chromesetcookie

Can't set a cookie in Chrome 5


Since today I am facing a tricky issue with Google Chrome that I've just updated to v5.
I have a user login process running on my website. Everything works fine on FF 3.6.x and IE 7, but I just can't set any cookie in Google Chrome 5. I'm mentioning 5 because it worked very well before on v4.

My PHP script looks like that:

  $cook = setcookie($cookieName, $value, $expires, '/', '.'.$domain);
  var_dump($cook, isset($_COOKIE[$cookieName]));

I even tried the alternative setrawcookie without any result.

  $cook = setrawcookie($cookieName, $value, $expires, '/', '.'.$domain);
  var_dump($cook, isset($_COOKIE[$cookieName]));

FF 3.6.x and IE7 output:

bool(true) bool(true)

Whereas Chrome v5 outputs:

bool(true) bool(false)



And obviously I see not trace of this cookie in Google Chrome 5. Any idea? =/

Cheers,
Nicolas.


Solution

  • You can check cookies by entering javascript:alert(document.cookie) into address bar.

    Cookie will be sent to server on 2nd request. [browser request(no cookie)]->[server response(set cookie)]...[browser request(cookie, if valid)]->... So you should see the cookie in $_COOKIE by refreshing the testpage.

    Also check if your parameters are right. (time in future and domain is your domain)