« PHP mod_rewrite and .htaccess tutorials | Main | FeedBurner's Feature Names Need an Overhaul »

PHP Session Cookies Across Subdomains and Multiple Domains

I was looking into how to make sessions work across multiple subdomains and found this post to be most helpful.

PHP Session Cookie Multiple Domains

My Fix

So you need to change the php session configuration option for session.cookie_domain from the default of “” (which inserts your hostname) to:

“.domain.com”

You can do this with: session_set_cookie_params() before doing your session_start() or if you have php start your sessions for you automatically you might consider throwing:

php_value session.cookie_domain ".domain.com"into the .htaccess file for the site. If you put the .htaccess file in the directory for xxx.domain.com then all sessions started on xxx.domain.com will be shared on all other domains like www.domain.com. This means however that sessions started in www.domain.com won’t carry over unless the .htaccess file is also present in it’s root directory.

Important Note

The first dot in “.domain.com” is not always nessesary however for support of all browsers it is suggested.

Technorati Tags: , , , ,

Comments

Federico

This was the work of a genius!
Thank you very much!

Mauricio

Your suggest work with FF but Not worked with IE, maybe you have a solution for IE.

kiran

Very helpful. thanx...........

Prmaod

Hi,

This is what i was looking for sharing the same session for my 96 subdomains. fantastic article. Keep it up

Neeraj

Thanks

seo free

Thanks lot..helped me lot...

Endi

Thanks. Very helpful article!

seo

Great fix but as already posted does not work in IE. Does anybody have any suggestions?

Anders

Thank you so much.

This really helped me out :)

siva

Thanks.......

Norris Ewelike

I'm amazed that a comment from 2006 is still relevant. what else in IT is the same for 4 years? :)

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In.