如果在我的网站上用于会员登录的会话。如果我在没有登出我的会话的情况下关闭了系统,会话维护将持续到第二天。如何清除会话。
在我的配置文件。我有以下代码:
config code:-
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'sitename',
'sourceLanguage' => 'sys',
'language' => 'en',
'preload'=>array('log', 'PreloadCms'),
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
'application.extensions.easyimage.EasyImage',
'zii.behaviors.*',
),
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'admin',
)
) + require(dirname(__FILE__).'/modules.php')
,
'components'=>array(
'PreloadCms' => array (
'class' => 'application.modules.cms_core.components.PreloadCms',
),
'user'=>array(
'class' => 'WebUser',
'allowAutoLogin'=>false,
),
)
);
-
public function authenticate()
{
$user=Signup::model()->findByAttributes(array('varEmail'=>$this->username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($user->varPassword!=$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->errorCode=self::ERROR_NONE;
$this->_id=$user->intId;
Yii::app()->session['id']=$user->intId;
$this->username=$user->varEmail;
}
return $this->errorCode==self::ERROR_NONE;
}
如果您在认证方法中登录用户,则不太正确,最好使用另一种方法来设置会话,如默认的yii LoginForm。
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate(); // Authenticate just checks if a user exists.
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // Set here the session life.
Yii::app()->user->login($this->_identity,$duration); // Use this method to proper login the user
return true;
}
else
return false;
}
更多详细信息请查看:http://www.yiiframework.com/doc/guide/1.1/en/topics.auth
确保遵循正确的yii模式,不要重新发明轮子。