0

I'm setting a cookie with PHP in www.mysite.com/CookieTest.php like so:

setcookie( "test", "value", time( ) + 259200000, "/" );

which works fine and I can see the cookie in the settings in Chrome. I then try and read the cookie in www.mysite.com/Login.php like so:

if( isset( $_COOKIE[ "test" ] ) == false )
{
    echo "error";
}

which works fine with http, but not https. The above always returns false, and when I try

print_r( $_COOKIE );

it prints an empty array, even though I can see that there are 5 other cookies set on my site's domain in Chrome.

I'm using ajax in jquery to make the request to both CookieTest.php and Login.php using https. I have set the Access-Control-Allow-Origin header and I'm not getting an error about the origin so I don't think that's the problem.

Joe Boris
  • 487
  • 3
  • 8
  • 15

1 Answers1

0

Unless you used the secure flag while setting the cookie, your cookie should be sent with both http as https.

You need to double-check that your domain name is exactly identical in both cases. Check for example if you are not using http://www.yourdomain/ (with www.) when setting the cookie and https://yourdomain/ (without www.) when trying to read the cookie.

nl-x
  • 11,762
  • 7
  • 33
  • 61