I have two questions. I understand that if I specify the domain as .mydomain.com
(with the leading dot) in the cookie that all subdomains can share a cookie.
Be careful if you are working on localhost ! If you store your cookie in js like this:
document.cookie = "key=value;domain=localhost"
It might not be accessible to your subdomain, like sub.localhost
. In order to solve this issue you need to use Virtual Host. For exemple you can configure your virtual host with ServerName
localhost.com
then you will be able to store your cookie on your domain and subdomain like this:
document.cookie = "key=value;domain=localhost.com"