当用户打开站点并登录到站点时,我正在使用 Yii 框架www.dominname.com
,身份验证或用户会话数据不同,
http://dominname.com
因此用户在打开 HTTP 时必须再次登录,我可以进行身份验证登录吗?在 WWW 和 HTTP 上完成或在 WWW 和 HTTP 之间共享会话数据。Yii 有什么配置可以解决这个问题吗?
如果用户检查rememberMe
其他用户将不会登录,此代码对我有用有谁知道如何解决这个问题?
主/配置
'user' => array( // enable cookie-based authentication 'class' => 'WebUser', 'allowAutoLogin' => true, ), 'session' => array( 'savePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../session', 'cookieMode' => 'allow', 'cookieParams' => array( 'path' => '/', 'domain' => '.domainname.org', 'httpOnly' => true, ), ),
组件/WebUser
class WebUser extends CWebUser { public $identityCookie = array( 'path' => '/', 'domain' => '.domainname.org', ); public function init() { $conf = Yii::app()->session->cookieParams; $this->identityCookie = array( 'path' => $conf['path'], 'domain' => $conf['domain'], ); parent::init(); } public function logout($destroySession = true) { if ($this->allowAutoLogin && isset($this->identityCookie['domain'])) { $cookies = Yii::app()->getRequest()->getCookies(); if (null !== ($cookie = $cookies[$this->getStateKeyPrefix()])) { $originalCookie = new CHttpCookie($cookie->name, $cookie->value); $cookie->domain = $this->identityCookie['domain']; $cookies->remove($this->getStateKeyPrefix()); $cookies->add($originalCookie->name, $originalCookie); } } parent::logout($destroySession); } }