Changing subdomain while logged in

I have a problem of keeping a user logged in when changing subdomains. When I login in example.com then move to foo.example.com I am no longer logged in but when I return to example.com I am still logged in. How can I fix this?

You must modfiy cookie params of session and user component (this only when using auto-login):




'components' => array(

   ...

   'session' => array(

      'cookieParams' => array('domain' => '.example.com'),

   ),

   ...

   'user' => array(

      'identityCookie' => array('domain' => '.example.com'),

   ),

   ...

),



Make sure there is a dot before the actual domain. Means the cookie is available on all subdomains.

How about the setState? Does this affect it?

No should work as usual.

More than a year later… and still i can’t get logged in. :blink:

No matter what I tried so far, I can’t get beyond that login page.

What if it’s a second-level domain like .co.uk? What values do I have to put in cookieParams and identityCookie if my domain is “example.co.uk” or “sub.example.co.uk”? The site itself is on a shared host and in a subdirectory of the account’s root dir though I don’t think this is the problem.

— never mind problem solved with CDbHttpSession —

it’s okay as this login is for a limited amount of editors only so i don’t mind db sessions. also, it’s the first time i used this with yii so yii-hah! done that too.

still it’s bugging me why the cookies didn’t work. i may give it another try later on just to figure out why it wasn’t working on that particular server side. all config params seem to be alright and the cookie path is 777. maybe i just need a break.