• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfcookie help

Explorer ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

If I set a cookie from www.mydomain.com and set a cookie with the same name at mydomain.com - it will show as 2 different cookies (one for each site).

How can I let coldfusion know those are the same locations and not 2 different cookies? As it is now, my site works if they use the www. but doesn't work without the www.

Thanks for your help.

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

You need to use the DOMAIN attribute of the CFCOOKIE tag to set the domain you want to set the cookie for - make sure it's always set for mydomain.com regardless of the URL they're browsing to and it'll be available at all times.

You might want to consider just using a rewrite engine to redirect people from the non-www site whenever they browse it if it's causing a problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

Actually, to do this properly you need to set the cookie with domain=".mydomain.com". Notice the dot (.) at the beginning of the value. This tells the browser to use that cookie for the domain and every host/subdomain of that domain.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

What will that do to my local testing? I'm using cookies for logins.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

If your local testing domain is local.mydomain.com then it will work fine. If your local testing is some other domain (like localhost) then it will not work. 

I recommend trying to make your local domain something like local.mydomain.com. It's quite easy t do if you are using Apache or IIS.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

LATEST

Otherwise, you can always resort to creating an environmental-aware application variable to store the domain string based on what environment (local, production) the code is executing in.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation