登录后未保存 Yii 框架会话 [英] Yii Framework Session Not Saved After Login
问题描述
我们在/rpotected/components/UserIdentity.php 中有以下函数:
We have the following function in /rpotected/components/UserIdentity.php:
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 中的一个片段:
Here's a snippet from /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;
}
问题:登录后,单击我的个人资料"链接会提示再次登录.因此,会话似乎没有存储/保存登录凭据并在登录生命周期中携带它们.
Problem: Upon login, clicking on My Profiles link prompts for login again. Thus, it seems that the session is not storing/saving the login credentials and carrying them through the login lifespan.
应该如何修改身份验证功能,以便存储会话信息并继承登录凭据?
How should the authenticate function be modified so that the session information is stored and so that the login credentials are carried forward?
推荐答案
请检查 "session.cookie_lifetime" php.ini 中的值
please check "session.cookie_lifetime" value in php.ini
session.cookie_lifetime = 2592000
这篇关于登录后未保存 Yii 框架会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!