Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a cookie on the TLD from a subdomain

I am pretty new to this cookie stuff. I have a requirement where I need to set a cookie on the TLD (www.example.co.uk) from one of the subdomains (sub.example.co.uk) using Javascript. First of all, is it possible? if yes, how do I go about doing that? Any help on this would be highly appreciated.

Thanks, L

like image 206
lshettyl Avatar asked Nov 25 '25 23:11

lshettyl


1 Answers

I think you are confused about the definition of a TLD. You cannot set a cookie on a TLD. You can try to set a cookie on a different domain, but the browser may or may not accept it (look into the P3P header). I would set it in a shared domain. In your example, it would be .example.co.uk and would work for www.example.co.uk and sub.example.co.uk.

Try this (untested):

document.cookie = "name=value; expires=date; path=path; domain=.example.co.uk";
like image 186
gpojd Avatar answered Nov 27 '25 13:11

gpojd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!