I create a bunch of cookies for authentication purposes and a part of the website allows the users to navigate to the UK part of the site. This is enabled by having a uk prefix in the domain. (e.g uk.domain.com).
I basically have a small script that checks to see if the subdomain is called UK then I deliver the UK content.
How can I make it so all the cookies on domain.com transfer to uk.domain.com?
I've tried ...
... setting the cookie to the just root domain
setcookie("auth", "blahblah", time() + 123, "/", "localhost")
... adding a dot to the beginning of the domain
setcookie("auth", "blahblah", time() + 123, "/", ".localhost")
... creating the cookie on both domains
setcookie("auth", "blahblah", time() + 123, "/", "localhost")
setcookie("auth", "blahblah", time() + 123, "/", "uk.localhost")
... creating cookies without any domain or path.
setcookie("auth", "blahblah", time() + 123, "/")
setcookie("auth", "blahblah", time() + 123)
I just can't seem to get it to work.
Found out that you cannot set localhost as a cookie on chrome. It needs to be a registry controlled domain and not an IP or intranet hostname.
I found a workaround by basically turning localhost into a domain.
I added this to the host file (c:\windows\system32\drivers\etc\hosts) -
127.0.0.1 localhost.com
127.0.0.1 uk.localhost.com
then created the cookies with the localhost domain
setcookie("auth", "blahblah", time() + 123, "/", "localhost.com")
This allowed me to access the auth cookie from http://uk.localhost.com (or pretty much any subdomain).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With