Posts Tagged ‘bootstrap’
Set the session cookie to the top level domain
Posted by primeminister | Filed under Cake-Toppings
I have an app that uses multiple sub domains besides the www.domain.com like computer.domain.com and books.domain.com, etc.
What I wanted is to set the session cookie to the higher level domain ‘domain.com’ so the session cookie will be valid through all sub domains.
In the CakeSession class (which is the parent of the SessionComponent) you can set the path but not the domain.
After talking with ADmad, Jurian and kabturek on IRC we found out that the session.cookie.domain is never set by the CakeSession handler so you can set it yourself!
ini_set('session.cookie_domain', '.domain.com');
So set the top domain through ini set in your APP/config/bootstrap.php and all will be set but not without settings the Session.security level to ‘low’ otherwise the referer_check will be set to the current HTTP_HOST in the CakeSession object line 441.
So in the APP/config/core.php:
Configure::write('Security.level', 'low');
Now the session cookie will be valid for all your subdomains and the top level domain.
Cheers!
p.s. Sharing the same session between multiple APPs? http://teknoid.wordpress.com/2008/10/05/sharing-cakephp-session-with-another-app/