Jump to content

Sessions across subdomains


Netpepper

Recommended Posts

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:

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

and

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

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:

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

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!
Link to comment
https://forums.phpfreaks.com/topic/12519-sessions-across-subdomains/
Share on other sites

[!--quoteo(post=386313:date=Jun 21 2006, 11:39 AM:name=benji87)--][div class=\'quotetop\']QUOTE(benji87 @ Jun 21 2006, 11:39 AM) [snapback]386313[/snapback][/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\" /]
[!--quoteo(post=386319:date=Jun 21 2006, 12:28 PM:name=benji87)--][div class=\'quotetop\']QUOTE(benji87 @ Jun 21 2006, 12:28 PM) [snapback]386319[/snapback][/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...

Archived

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

×
×
  • 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.