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.

3
  • 1
    Read this [Reading cookies via HTTPS that were set using HTTP][1] [1]: stackoverflow.com/questions/2163828/… Commented Mar 21, 2015 at 8:17
  • Please show the jquery ajax code Commented Mar 21, 2015 at 8:45
  • Thanks for the info, I'll be busy all day today but I'll post more info later tonight Commented Mar 21, 2015 at 12:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.