Jump to content


Photo

Sessions across subdomains


  • Please log in to reply
5 replies to this topic

#1 Netpepper

Netpepper
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 06:48 AM

Hi,

I am trying to get Sessions passed through to different subdomains. I have tried about everything I could find on the internet, but absolutely nothing seems to work...

What I need is to check if a user is logged in on various subdomains. So, if the user logs in via sub1.domain.co.za, he should still be logged in when he opens sub2.domain.co.za or www.domain.co.za, or vice versa.

I have tried to "tell" the system in various ways that the session is valid for the entire ".domain.co.za" range, just as I would do for cookies. With actual cookies, I have no problems at all, but with sessions it just does not want to work. I have tried these methods for registering the session:

ini_set("session.cookie_domain", ".domain.co.za");
session_start();
$_SESSION["test"] = "this is a test";

and

session_set_cookie_params(time() + 3600,"",".domain.co.za");
session_start();
$_SESSION["test"] = "this is a test";

I have also tried the session_register() function. This does initialise the session and register the variable "test", however, if I try to access the session data from a different subdomain with:

session_start();
echo $_SESSION["test"];

no value is returned. Even if I use ini_set("session.cookie_domain", ... ) or session_set_cookie_params() and set the session domain to ".domain.co.za" once again, I cannot retrieve the value for the previously set variable "test". Instead, a new session is started. If I leave session_start() out, no session is available at all.

I am sure that I'm doing something wrong, but what???

My PHP version is 4.4.2, standard setting for session.cookie_domain is NULL, Apache version 1.3.36

Please help me!

#2 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 09:39 AM

As far as im aware it is impossible to carry sessions over to another domain. That could cause all kind of problems for people if you think about it.

#3 Netpepper

Netpepper
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 10:18 AM

[!--quoteo(post=386313:date=Jun 21 2006, 11:39 AM:name=benji87)--][div class=\'quotetop\']QUOTE(benji87 @ Jun 21 2006, 11:39 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
As far as im aware it is impossible to carry sessions over to another domain. That could cause all kind of problems for people if you think about it.
[/quote]

Thanks. Would it be impossible even if it concerns subdomains within the same domain? Then what is the purpose of the "domain" setting for Sessions in PHP, I wonder? [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

#4 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 10:28 AM

I dont know as im not expert in sessions varibles. But the only was i could see it working is if the domains route was in the same place??

#5 Netpepper

Netpepper
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 10:36 AM

[!--quoteo(post=386319:date=Jun 21 2006, 12:28 PM:name=benji87)--][div class=\'quotetop\']QUOTE(benji87 @ Jun 21 2006, 12:28 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I dont know as im not expert in sessions varibles. But the only was i could see it working is if the domains route was in the same place??
[/quote]

That's the thing; the subdomains are hosted on the same server; they are in different subfolders of the main folder (public_html). Therefore, I do not understand why it is not working...

#6 Netpepper

Netpepper
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 June 2006 - 09:56 AM

Anyone? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users