Page 1 of 1

session is not working between domain and sub-domain

Posted: Wed May 09, 2007 5:38 am
by amir
Hello,
I am working on a site which has two domain part e.g.

abc.com and xyz.abc.com ( sub-domain of abc.com )

when one get logged in at xyz.abc.com, It store username in the session so that if any user after logged in at sub-domain, manually enter abc.com in the address bar, he should be redirected to xyz.abc.com. But session is not working between these domain and sub-domain.

Please advise.

Thanks a million =)

Posted: Wed May 09, 2007 6:02 am
by mentor
Set the value for session.cookie_domain. Before initializing session (session_start()) put this line

ini_set ( 'session.cookie_domain', '.abc.com' );

for more info visit http://www.php.net/manual/en/ref.sessio ... kie-domain

Posted: Wed May 09, 2007 8:16 am
by amir
thanks for your reply. I tried this but it does not work for me. I have searched here and there and come to know this works if we create session in TLD and use in SLD but I want to create login session in sub-domain e.g. abc.xyz.com and then i want to check that session in TLD e.g. xyz.com

Please advise

Posted: Wed May 09, 2007 10:06 am
by volka
ini_set( 'session.cookie_domain', 'xyz.com' ); or session_set_cookie_params() should take care of that. You have to set the parameters each time before calling session_start() (or use a per-directory method).

Posted: Wed May 09, 2007 10:09 am
by amir
Could you please explain ' per-directory method ' because I have tried other ways.

Posted: Sat May 12, 2007 3:15 pm
by volka