Skip to main content
January 12, 2011
Question

Maintain session across subdomains

  • January 12, 2011
  • 4 replies
  • 1410 views

Hey all

I am working on a website that utilizes session data. The problem is that session data does not seem to be shared over subdomains. For example, my website

is available at.

http://mysite.com

and

http://www.mysite.com

the DNS points to the exact same place, they are the same website. But if you login on one, your session information isn't available on the other. For now as a workaround I just added a redirect in my application.cfm that says if you arn't on the www version, go to it but that seems rather hackish. Am I missing something? Is there an easy way to say a persons session is valid for the domain and all subdomains?

    This topic has been closed for replies.

    4 replies

    BKBK
    Community Expert
    Community Expert
    January 12, 2011

    To maintain sessions across subdomains, I think it's sufficient to enable J2EE sessions in the Administrator. I am assuming you have enabled session management in the usual way. That is, using Application.cfc or the cfapplication tag in Application.cfm.

    Community Expert
    January 12, 2011

    By default, cookies are host-specific. You can use the setdomaincookies attribute of your application properties or CFAPPLICATION tag to change this.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    Participating Frequently
    January 12, 2011

    Not the answer to your question, but SEO best practices say you should pick one or the other (with or

    without WWW) and permanently redirect the one you didn't pick to the other at the web server (Apache/IIS) level.  Search engines will pentalize you if

    you don't because they see http://mysite.com/index.cfm and http://www.mysite.com/index.cfm as two different pages.

    January 12, 2011

    That is good information, thank you. I have not done much any reading into SEO so that is something I definitly didn't know. I'll look into doing a redirect as you

    mention.


    Inspiring
    January 12, 2011

    Hope this blog will help you to troubleshoot your issue,

    http://www.bennadel.com/blog/730-Testing-ColdFusion-Session-Cookie-Acceptance.htm