Jump to content

Create cookie on domain and all subdomains


uworlds
 Share

Recommended Posts

Hello,

Is it possible at all that when a cookie is created, either on a subdomain or domain, that it places a copy of it on all other subdomains, compared to passing a query string from page to page with a view to achieving the same?

Kind regards

Link to comment
Share on other sites

When creating a cookie in Javascript, setting the domain component to your top level domain will make the cookie accessible to all subdomains. Here is an example:

document.cookie = "username=John Doe; domain=example.com";

The above cookie will work on example.com and also subdomain.example.com.

Link to comment
Share on other sites

Thank you so much for this, I really appreciate it!

May I please ask you as well, if the subdomain is on a different IP address than the main domain (I can't get around that), will that still make the cookie available to all subdomains seen in the browser, or do I need to create a different cookie for each subdomain that has a unique IP address?   

Kind regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...