View Full Version : setting cookie on 2 locations

11-16-2007, 08:12 PM
How can i set a cookie on 2 different locations? The problem i have now is that if i go to http://www.domain.com it recognize the cookie, but when i go to http://domain.com (without the www.) the cookie doesn't show up... So is there a way i can set them on both locations?

11-16-2007, 08:37 PM
A) You should actually pick one version of the domain name and use that in all links on your site and redirect visitors from the version you don't generally want to the version you do want to use. By being consistent and always using only one version, it will help your search engine page rank (or so I have been told.)

B) By default, the session.cookie_domain setting (none) will cause the session cookie to only match the domain where the cookie was set at. From the manual -

session.cookie_domain string
session.cookie_domain specifies the domain to set in session_cookie. Default is none at all meaning the host name of the server which generated the cookie according to cookies specification.By setting the session.cookie_domain to be .domain.com (including the leading dot), it will match both www.domain.com and domain.com. See the following from the setcookie() description in the manual for more information -
The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain