0

I'm trying to set a cookie with this lines

if(!isset($_COOKIE["testAgain"]))
        setcookie("testAgain", mt_rand());

The problem is that, even if I can see in the response headers the following lines:

Set-Cookie: testAgain=15146202

When I change the page, the cookie is not in $_COOKIE and it tries to set it again.

Why is this happening?

steo
  • 4,586
  • 2
  • 33
  • 64
  • Have you checked if your browser has cookies enabled? Are you trying in incognito browser? – Thamilhan Sep 06 '16 at 09:18
  • Yes, the browser have cookie enabled, as long as I am able to set them Client side. No, did not tried incognito browser – steo Sep 06 '16 at 09:20
  • 2
    Have you tried specifying a domain and path for the cookie? – TMH Sep 06 '16 at 09:20
  • 1
    It looks like a Browser problem. Are you running on Localhost? It could be this bug. http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain – nv1t Sep 06 '16 at 09:23
  • @nv1t it seems to be that. Going to check it right now – steo Sep 06 '16 at 09:24
  • seems to be a chrome bug for localhost, in firefox I see it – steo Sep 06 '16 at 09:30

0 Answers0