SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session across subdomains (and on localhost)

    I have recently added some subdomains to my localhost box for testing:

    http://localhost
    http://forums.localhost

    For some reason, the session_id that gets propogated at http://locahost does not carry over to the http://forums.localhost. When I go to any of the subdomains I get another session_id. Does anyone know why this is? I store all my session data in mySql. I am looking to have just one session_id carry me through the entire site.

    Any help?

    Thank you in advance,

    Piet

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Session across subdomains (and on localhost)

    I think this is to do with the way that cookies work - you have one cookie per domain (otherwise any site could look at all your cookies without your permission).

    You could try using cookie-less sessions, or not using a subdomain.

    Hadley

  3. #3
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about it, but isn't there something like .localhost , to define the cookies on the whole domain+subdomains ?

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Netscape Cookie Spec:
    domain=DOMAIN_NAME
    When searching the cookie list for valid cookies, a comparison of the domain attributes of the cookie is made with the Internet domain name of the host from which the URL will be fetched. If there is a tail match, then the cookie will go through path matching to see if it should be sent. "Tail matching" means that domain attribute is matched against the tail of the fully qualified domain name of the host. A domain attribute of "acme.com" would match host names "anvil.acme.com" as well as "shipping.crate.acme.com".
    That sounds like you should be able to set yourname.tld and match to alpha.yourname.tld, and beta.yourname.tld. Whether or not this is still the case, I'm not sure...

    The Unofficial Cookie FAQ
    Domain
    The domain parameter takes the flexibility of the path parameter one step further. If a site uses multiple servers within a domain the it is important to make the cookie accessible to pages on any of these servers.

    ... domain=www.myserver.com ...

    Cookies can be assigned to individual machines, or to an entire Internet domain.

    The only restrictions on this value is that it must contain at least two dots (.myserver.com, not myserver.com) for the normal top-level domains, or three dots for the "extended" domains (.myserver.ny.us, not myserver.ny.us)
    This basically says yes, your .localhost should work on a live site, but may locally not because there aren't enough periods.
    Andrew Thompson
    VPHost.com, part of the Untapped Resources Network.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •