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: .htaccess, php, sessions, cookies, subdomains
This was the work of a genius!
Thank you very much!
Posted by: Federico | Mar 25, 2007 at 01:08 PM
Your suggest work with FF but Not worked with IE, maybe you have a solution for IE.
Posted by: Mauricio | Aug 31, 2007 at 08:39 AM
Very helpful. thanx...........
Posted by: kiran | Sep 02, 2007 at 09:18 PM
Hi,
This is what i was looking for sharing the same session for my 96 subdomains. fantastic article. Keep it up
Posted by: Prmaod | Jul 17, 2008 at 09:20 AM
Thanks
Posted by: Neeraj | Sep 01, 2008 at 12:32 AM
Thanks lot..helped me lot...
Posted by: seo free | Jun 28, 2009 at 11:49 PM
Thanks. Very helpful article!
Posted by: Endi | Jul 10, 2009 at 12:05 AM
Great fix but as already posted does not work in IE. Does anybody have any suggestions?
Posted by: seo | Oct 12, 2009 at 03:44 AM
Thank you so much.
This really helped me out :)
Posted by: Anders | Dec 10, 2009 at 02:40 AM
Thanks.......
Posted by: siva | Mar 20, 2010 at 04:42 AM
I'm amazed that a comment from 2006 is still relevant. what else in IT is the same for 4 years? :)
Posted by: Norris Ewelike | Aug 26, 2010 at 12:24 AM