I have been trying to find out a way to share cookies across multiple subdomains.
Setting the cookie like:
setcookie('token', base64_encode(serialize($token)), time()+10800, '/', '.mydomain.com');
does exactly that. But there is a slight problem here. This will share the cookie across all subdomains.
My problem is that I have other environments (Dev and test) set up on 2 subdomains. I am looking for a way to share cookies across "Selective" subdomains. i.e. share across some subdomains, and not share amongst others. I am not sure if anything like this exists.
Any help is appreciated. Thanks.
Please everyone note that you can set a cookie from a subdomain on a domain. But you CAN'T set a cookie from a domain on a subdomain.
Seems to have worked, so ASP.NET session cookies on different subdomains still count as first party. A cookie set on a website that is loaded in an iframe of a different website is considered to be a third party cookie to the parent website.
Host Only cookie means that the cookie should be handled by the browser to the server only to the same host/server that firstly sent it to the browser.
As far as I'm aware you can either share across all subdomains using '.mydomain.com' (as you are doing) or you have to be specific and target only one subdomain using, for example, 'test.mydomain.com'.
You can also use some tricks, or workarounds, like prefixing the cookie name and then doing the logic server side, but I'm not sure if this si the solution you are looking for.
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