开发者

How to make session/cookies work in all subdomains in Yii

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 session work in all subdomains?

Update:

开发者_运维百科

I found each subdomain has a different session id...

Update:

I found I could only login in several domians like 'bench' and 'post', but cannot login in 'book' and other domains. Really strange.


You could set it in yii config/main.php file, like i did. (i'm not sure if you still have to change php.ini file, but i would say "no", because this configuration below fixed my problem).

protected/config/main.php

...
'components' => array( 
    ...        
    'user'=>array(
        ...    
        'identityCookie' => array('domain' => '.mydomain.com', //note dot before domain name 
        // identityCookie same as "session->cookieParams->domain"
    ),
    'session' => array(
        'autoStart'=>true,
        'cookieParams' => array('domain' => '.mydomain.com'),
    ),
    ...
)
...



You could use PHP's session.cookie_domain value and set it to your top level domain (.domain.com). By editing php.ini or setting using ini_set('session.cookie_domain', '.domain.com');

Good luck :)
Shai.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜