对不起,因为我的英语不好。这是我的困惑,我试图在Yii中创建基于Cookie的登录,我在main.php中有以下代码
'allowAutoLogin'=>true,
并在LoginForm.php中
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->userName,$this->password);
$this->_identity->errorCode = $this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 :0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
{
return false;
}
}
但是,当我登录网站时,浏览器关闭后,用户被注销,所以即使您关闭浏览器,也可以请我帮助保持用户登录状态。
也许您的登录表单中没有“记住我”复选框。尝试在LoginForm.php中执行以下代码
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->userName,$this->password);
$this->_identity->errorCode = $this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
// $duration = $this->rememberMe ? 3600*24*30 :0; // 30 days
$duration = 3600*24*30; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
{
return false;
}
}
附加
或者,请检查php.ini中的“ session.cookie_lifetime ”值
session.cookie_lifetime = 2592000
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句