When answering we should keep in mind that in the future, others may read the conversation looking for help (without having to ask the same questions again). But I am finding that instead of answering the question "How to make a sessions available across subdomains", we are getting how to send a session ID across domains which doesn't really answer the question.
While the examples can (and do) work for most situations, mine is a little different as the user(s) will not necessarily be following a link to other sub domains. I need it so that user can visit sub1.domain.com, then close browser, and at a later time (before original session expires) go to sub2.domain.com and still be "logged in". This wont work by passing an id in a link, or other.
One question that kind of arose for me out of the comments already posted, how would you save a session ID in SQL DB, and be able to pull the right one out later? I mean, walk it thru with me: The whole thing here is to be able to identify the specific user - so they must be assigned an ID. The Session ID does just that. But most people trying to get cross subdomain sessions dont want their users to login multiple times for each subdomain, which defeats the whole point of having the session in the mysql database because we need to be able to identify the user.
So how is it done? I guess now that I think about it, one idea would be to allow your login script to use $_GET for username / pass, and have the script login on each subdomain via:
$login_sub1 = file_get_contents("sub1.domain.comv");
$login_sub2 = file_get_contents("sub21.domain.comfile_get_contents("sub1.domain.com");
Then you could eregi the pages for success / error messages....but that's a TON of work for such a simple task.
I have been looking at every single result on Google for the last 3 hours and can't figure this out.
I have edited php.ini files, and the php files themselves, I've called my hosting company, I have called friends, I just can't figure this out. But I'll tell you what, if I can figure this out I'll write a step by step guide.
Here is what I have:
Apache / PHP with Host Gator (August 21, 2009).
php.ini file in the root of each subdomain and the main domain, each ini file is just about the same.
I have edited lines -
session.cookie_domain = .domain.com
session.save_path = /home/user/domains/sessions
In sub1.domain.com I have a login that stores the userid in $_SESSION['userid'], and at the top I have:
//ini_set("session.cookie_domain", ".domain.com");
session_start();
At sub2.domain.com, I have this at the top:
//ini_set("session.cookie_domain", ".domain.com");
session_start();
echo "SESSION USERID: \"".$_SESSION['userid']."\"";
sub2.domain.com will not show anything after logging into sub1.domain.com. I have tried un commenting the ini_set lines, different combinations of stuff...I am missing something important and can't figue out what.
If you have an idea I'd love to hear it. Thanks in advance!!
~John