Skip navigation
RichieWhite
Currently Being Moderated

cfcookie help

Oct 25, 2011 9:00 AM

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.

 
Replies
  • Currently Being Moderated
    Oct 25, 2011 9:32 AM   in reply to RichieWhite

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 25, 2011 10:00 AM   in reply to Owain North

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 25, 2011 3:12 PM   in reply to RichieWhite

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 27, 2011 10:42 AM   in reply to 12Robots

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points