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";
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!