0

I'd like to understand how does domain parameter of setcookie function works. I've the following code:

setcookie.php:

setcookie("cookie_4", "c4", time()+3600, "", "home_domain.com");
setcookie("cookie_5", "c5", time()+3600, "", "sub2.home_domain.com");

When i make the request form http:\\home_domain.com\setcookie.php the cookie_4 is available in both http:\\home_domain.com\getcookie.php and http:\\sub2.home_domain.com\getcookie.php requests but cookie cookie_5 isn't available from http:\\sub2.home_domain.com\getcookie.php even if it's explicitly set for domain sub2.home_domain.com?

Ringger007
  • 25
  • 3
  • 1
    https://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain – fraggley May 09 '20 at 12:11
  • 1
    I cannot reproduce it on Windows 10, neither in Firefox nor in Chrome. What's your environment? Have you changed default cookie settings? Are you positively sure your verification is correct? [Screenshot](https://i.imgur.com/7kQzoJY.png) – Álvaro González May 09 '20 at 13:28
  • @ÁlvaroGonzález Yes, im on win10 64-bit, Firefox. I haven't changed any cookie settings and yes, I've checked it several times. – Ringger007 May 09 '20 at 14:19
  • I suppose the names and values have been redacted and you possibly have additional code. It could really be anything: your company's security software filtering out HTTP headers for certain domains, some other piece of code that's overwriting some, a malformed string... To my knowledge, the code you've shared should work flawlessly. – Álvaro González May 09 '20 at 14:38
  • @ÁlvaroGonzález "the code you've shared should work flawlessly" - so You have _cookie_5_ set when making request _sub2.home_domain.com\getcookie.php_ after setting it by _home_domain.com\setcookie.php_? – Ringger007 May 09 '20 at 17:37
  • Oh, my excuses, I misread your description. Setting a cookie for `sub2.home_domain.com` from `home_domain.com` is something you cannot do. There's a good [answer](https://stackoverflow.com/a/57803192/13508) in the question linked by fraggley. – Álvaro González May 09 '20 at 17:59

0 Answers0