Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Cookie Paths and Domains


Recommended Posts

There always seems to be a bit of confusion over these settings in configure.php files. People saying I set mine to this and it works fine, others say I have this and it works fine. You are all correct, here is the help from the setcookie function on the www.php.net website




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.


So even leaving the path as '' (an empty string) will work, when someone goes to your site they enter at the root directory, the cookie gets set by default as '/'




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. Refer to tail matching in the spec for details.


Majority of people only use www.yourdomain.com for a web site, so setting to 'www.yourdomain.com' is fine. Only if you need to have the cookie carried forward onto subdomains (mysub.yourdomain.com) do you NEED to set it as '.yourdomain.com', but setting yours as that if you only have www.yourdomain.com address will do no harm at all.


Hope this clears up a lot of confusion on this subject.



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...