Session For Subdomains And Multiple Domains At The Same Time?


I am currently setting cookieParams for my session in my config file to allow session to be used across subdomain:

array( 'domain' => '' )

I implemented a custom domain feature allowing my user to use any custom domain. With the above code, session does not work under a custom domain. If I take out the above code, session works under the custom domain, but session is not shared between subdomains.

Is there a way to make session work under custom domain while having subdomains share the session?


Try this:

'session' => array(

    'cookieParams' => array('domain' => ''),


'user' => array(


    'identityCookie' => array('domain' => ''),



Of course, all the domains must be on the same server. In case of different servers consider using shared sessin store like memcached.

Thanks for the reply. I don’t quite follow. I am using CDbHttpSession for session. With the code you provided, it seems that session is not working for custom domains i.e.

I ended up setting the cookieParams dynamically in my root Controller by looking at the request hostInfo

Yii::app()->session->setCookieParams( array('domain' => '') );