Answer the question
In order to leave comments, you need to log in
How to set cookies ONLY on the main domain?
When setting cookies:
setcookie("Data", $data, 0, "/", "example.com");
they still extend to subdomains. How can I make sure that these cookies are only on the main domain?
Note:
In RFC 2109, a domain without a leading dot meant that it could not be used on subdomains, and only a leading dot ( .mydomain.com ) would allow it to be used on subdomains.
However, modern browsers respect the new RFC 6265 specification and ignore any leading dot, which means you can use a cookie on subdomains as well as top level domains.
So if you set a cookie like the second example above from mydomain .com , it will be available for subdomain.mydomain.com and vice versa.
Answer the question
In order to leave comments, you need to log in
do not specify domain at all in setcookie, then it will not work on subdomains:setcookie("Data", $data, 1, "/");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question