Issue
This question is generally phrased as "How to share cookies across multiple subdomains" and the answer is generally to use the leading dot like so
setcookie( 'id', 0, time()+30*3600, '/', '.example.com' );
which means that the cookie is available to all subdomains of example.com
. However, the /
path I suspect adds the constraint that all subdomains must be physically under the same tree. The PHP documentation states
path
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
Is it possible to share cookies if one has two (Apache) Virtual Hosts set up with document roots at, for example
- www.one.example.com → /var/www/example1
- www.two.example.com → /var/www/example2
Solution
Yes it will work.
The path segments of the cookies are based on the URI.
www.one.example.com
and www.two.example.com
both have / as the URI. The cookie doesn't have anything to do with where the virtual host resolves to.
Answered By - Jay Prall
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.