後我們在/rpotected/components/UserIdentity.php以下功能:Yii框架會議不保存登錄
public function authenticate()
{
$username = $this->username;
$password = $this->password;
$user = Users::model()->find('username=? AND password=?', array($username, $password));
if($user === NULL){
$this->errorCode=self::ERROR_UNKNOWN_IDENTITY;
}else{
$this->username = $user->username;
sess('SESS_USER_INFO', $user->attributes);
//print_r(sess('SESS_USER_INFO'));
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
下面是從/protected/models/Users.php一個片段:
public function login()
{
if($this->_identity===null)
{
$username = $this->username;
$password = md5($this->password);
//echo "Username: ".$username."<br />Password:".$password;
$this->_identity=new UserIdentity($username, $password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 60*20; // 30 days
//print_r($this->_identity);
Yii::app()->user->login($this->_identity,$duration);
//echo "Login Successful";
return true;
}
else{
//echo "Error";
$this->addError('password','Incorrect username or password.');
return false;
}
問題:登錄後,單擊我的配置文件鏈接提示再次登錄。因此,會話似乎並不存儲/保存登錄憑證並在登錄使用期限內持有登錄憑證。
應如何修改驗證功能以便存儲會話信息並使登錄憑證繼續運行?
什麼是'SESS( 'SESS_USER_INFO',$用戶>屬性) 「session.cookie_lifetime」 值;'? – 2012-08-01 00:12:30
我在想它的目的是保存會話的登錄用戶屬性? – SidC 2012-08-01 01:53:48
刪除它,它可能與yii的會話處理衝突 – 2012-08-01 02:12:27