Need urgent help! How use cookies in all subdomain

I have several subdomains like ‘a.domain.com’,‘b.domain.com’ but I found that if i login at subdomain a, session/cookies won’t work in b, and i have to login again in ‘b.domain.com

How do I make login work in all subdomains? My site is going to run on the net, so it’s very urgent question. Can anyone help me out?

You need to set the cookie’s domain to .domain.com

Please note the preceding dot.

Question is where do i set it? I use Yii’s form to login and Yii automatically set cookies and session.

You should be able to set that via CWebUser.identityCookie. In your config, that should be in the components/user-stanza.

Seems not caused by cookie domain setting. Setting cookie domain name correctly doesn’t work…

I checked the cookie content, each subdomains has a different session id…

In addition to extending CWebUser, make sure to set the ‘id’ of your app in the config to be the same for all the sub sites, and then configure the cookie settings / session name in your components. Here is an example from a test setup I did:




  'id' => 'YiiTest',

  'components' => array(

    'session' => array (

      'class' => 'system.web.CDbHttpSession',

      'connectionID' => 'db',

      'sessionName' => 'YiiTestSession', 

      'sessionTableName' => '{{session}}',

      'autoCreateSessionTable' => FALSE,

      //'timeout' => 1440,

      'cookieMode' => 'allow',

      'cookieParams' => array(

        'path' => '/',

        'domain' => '.test.local',

        'httpOnly' => TRUE,

      ),  

    ),

  ),



Or basically just follow this guide.

I tried to follow the guide and I believe I did well. But I still can’t get it right. Whatever my settings are, once I set ‘domain’ => ‘.mydomain.com’ in cookieParams login will not work even on one single page.:(

I found that I could login in some domains like ‘bench’ and ‘post’, but cannot login in book and several other domains. Really strange.

:) Question solved. Should already be solved after taking Matt Kelliher’s advice, just because I forgot to clear the browser’s old cookies after i changed the setting