session is not working between domain and sub-domain

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

session is not working between domain and sub-domain

Post 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 =)
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post 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
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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).
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Could you please explain ' per-directory method ' because I have tried other ways.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply