Sessions get splitted

Discussion in 'PHP' started by casper, Aug 11, 2006.

  1. #1
    Hey guys,

    I have a problem and I am calling it 'Session splitting' since I have no other way to put it.

    When a user logs in on my website by visiting www.mywebsite.com the cookie will be stored for www.mywebsite.com . It does not store the cookie for mywebsite.com (without the www). How can I fix this?

    thx
     
    casper, Aug 11, 2006 IP
  2. talentcoder

    talentcoder Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The cookie name is defined within your web evironment. Modify it to what you want, or you can change it in your web script.
     
    talentcoder, Aug 11, 2006 IP
  3. casper

    casper Guest

    Messages:
    181
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think my webserver thinks business-web.org en www.busines-web.org are two different domains, and does therefore disallows access to 'both' session cookies. How can I get my webserver to think that business-web.org and www.business-web.org are the same thing? I tried

    
    ini_set('session.cookie_domain', '.business-web.org');
    
    Code (markup):
    but that's not working. Any other ideas on this matter?

    thx


    [edit]
    Weird, the code above does work on a different PC. Although I have removed the session with sessn_destroy, it looks like there are still some remains. Aaah, no problem, it works :D
     
    casper, Aug 11, 2006 IP
  4. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #4
    If you set a cookie then use this:

    setcookie("session_name", $var, time()+3600, "/", ".mywebsite.com");
     
    smatts9, Aug 11, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What you are describing isn't a 'bug' you can fix, it's a feature. www.yourdomain.com and yourdomain.com ARE in fact two different sites, for security, cookies are not meant to work cross border. Just picture the trouble that would cause on sites like blogspot.

    Just 301 all www to non www or the other way around and consistently link to one, not the other.
     
    T0PS3O, Aug 11, 2006 IP