Jump to content


This topic is now archived and is closed to further replies.


Sessions Across Subdomains

Recommended Posts

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 [/code]

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.
         setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
         setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRE, COOKIE_PATH);
      /* Login completed successfully */
      return true;
   } [/code]

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!

Share this post

Link to post
Share on other sites
we don't know what the session code is though. Are you using $_SESSION variables, or a DB? Or both?

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.