为什么用户在Yii中关闭浏览器后没有注销?

ijnw1ujt  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(153)

这个问题只在Chrome和Firefox中出现。Opera和Safari可以正常工作。登录时,我没有选中rememberMe选项。

允许自动登录设置为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));
}
lvjbypge

lvjbypge1#

在配置文件(protected/config/main.php)中,您可以将允许自动登录更改为false

'components' => array(
    'user' => array(
        // enable cookie-based authentication
        'allowAutoLogin' => false,
    ),

在这里阅读更多关于Yii登录状态的信息http://www.yiiframework.com/doc/api/1.1/CWebUser

相关问题