Setting cookies for multiple subdomains

Can I set a cookie for http://www.example.com from a PHP file located at https://secure.example.com ? I have a code that was provided to me that seems to be trying to do this. I was wondering if this is possible at all.

+7
cookies subdomain cross-domain
source share
2 answers

Web pages can only set cookies for the second (or higher) domain to which they belong.

This means that secure.example.com can read and set cookies for secure.example.com or .example.com , the latter of which can also be read and set using www.example.com

Last note: if a safe flag is set in the cookie, it can only be read and set via the https connection.

+9
source share

If you set the cookie domain to ".example.com", the cookie will work for all subdomains.

+3
source share

All Articles