Jump to content


Photo

Sessions Across Subdomains


  • Please log in to reply
1 reply to this topic

#1 shanparker

shanparker
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 June 2006 - 05:48 AM

This is my first post here - when I'm trouble shooting Yahoo searches often bring up threads here - so I thought I would join and see if you guys could help me with this problem I'm having (don't worry I'll have plenty more in the future!) I'm still somewhat knew to PHP so I'm still getting the hang of even the simple stuff. I posted this at another forum as well, and will just repeat it here to see if anyone can help!

---

I've been racking my brain with this and searching all over the internets and haven't been able to find a solution that I've been able to make work. I'm using the awesome login script for evolt.org. Works really well. However I've set up a subdomain with mod_writes on my site. So users have addresses - like [a href=\"http://my.website.com/user\" target=\"_blank\"]http://my.website.com/user[/a]

The script is using cookies and sessions and I need the sessions to carry across the the subdomains. However they are not and I can't get them to work. I've read up on several ways to fix the problem but none have worked. So I thought perhaps if I provided the script pieces here that maybe someone could help me.

In the constants.php file:
/**
 * Cookie Constants - these are the parameters
 * to the setcookie function call, change them
 * if necessary to fit your website. If you need
 * help, visit www.php.net for more info.
 * <http://www.php.net/manual/en/function.setcookie.php>
 */
define("COOKIE_EXPIRE", 60*60*24*100);  //100 days by default
define("COOKIE_PATH", "/");  //Avaible in whole domain


Then in the session.php file it sets the cookie here:
/**
       * This is the cool part: the user has requested that we remember that
       * he's logged in, so we set two cookies. One to hold his username,
       * and one to hold his random value userid. It expires by the time
       * specified in constants.php. Now, next time he comes to our site, we will
       * log him in automatically, but only if he didn't log out before he left.
       */
      if($subremember){
         setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
         setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRE, COOKIE_PATH);
      }
      /* Login completed successfully */
      return true;
   }

I tried changing the "/" to ".domain.com" like I saw suggested at several sites but I was still loosing my session at the subdomain.

Any help on this matter is appreciated. I know there's a solution. SOMEWHERE!

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 17 June 2006 - 08:25 AM

we don't know what the session code is though. Are you using $_SESSION variables, or a DB? Or both?
z..z..z..z..z..z..z..z..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users