此问题仅适用于Chrome和Firefox。 Opera和Safari工作得很好。 登录时,我不检查rememberMe选项。
allowAutoLogin 设置为TRUE
这是LoginForm模型的登录方法:
public function login()
{
if ($this->_identity === NULL)
{
$this->_identity = new UserIdentity($this->login, $this->password);
$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;
}
这是我的行动:
public function actionLogin()
{
$model = new LoginForm;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if (isset($_POST['LoginForm']))
{
$model->attributes = $_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if ($model->validate() && $model->login()) $this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login', array('model' => $model));
}
答案 0 :(得分:1)
在配置( protected / config / main.php )中,您可以将 allowAutoLogin 更改为 false
'components' => array(
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => false,
),
在此处阅读有关Yii登录状态的更多信息http://www.yiiframework.com/doc/api/1.1/CWebUser