SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Session Across Subdomains

    I'm trying to keep the same session alive across subdomains on the same machine. I've tried some of the conventional techniques quoted below (placed at the top of the page right after <?php), but none of them work. I know this is possible since I've seen it done on other sites, but I just can't seem to get it to work!

    Tried this, didn't work:

    PHP Code:
    ini_set("session.cookie_domain",substr($_SERVER[HTTP_HOST],3));
    session_start(); 
    Also tried this, didn't work:
    PHP Code:
    session_set_cookie_params(360000,'/','.domain.org');
     
    session_start();
    ob_start(); 
    (where .domain.org is my domain name, with a . before it!)

    And, also tried this, didn't work:
    PHP Code:
    session_set_cookie_params(360000,'/','.domain.org');
     
    session_start(); 
    Please help!

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2008
    Location
    NC
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this
    PHP Code:
    ini_set("session.cookie_domain"".mydomain.com"); 
    add it before the session.start() function on any page which creates the session cookie.

    Or, you can add:
    PHP Code:
    session.cookie_domain = .mydomain.com 
    to php.ini

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure you've cleared your cookies, then try again.

  4. #4
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked. Thanks! :-)


Tags for this Thread

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
  •