在存储的配置文件会话中使用Yii框架的处理如下:
'session' => array(
//'sessionName' => 'SomeSession',
'class' => 'CDbHttpSession',
'connectionID' => 'SomeConnection',
'autoCreateSessionTable' => false,
'sessionTableName' => 'SomeTable',
'autoStart' => 'false',
'cookieMode' => 'only',
'useTransparentSessionID' => false,
'timeout' => CSESSIONTIMEOUT,
'cookieParams' => array(
'path' => '/',
'domain' => '.somedomain.extension',
'expire' => time()+5256000,
'lifetime' => time()+5256000,
//'httpOnly' => true,
),
),
因此,当您看到会话存储在具有给定生命周期的数据库的表中时。但是,如果我检查数据库中存储的会话,它们在给定的生命周期内没有存储,那么它们的存储寿命为一年。
我在我们的应用程序中唯一可以找到一年的生命周期就是cookie。例如:
setcookie("cookie_name", $someValue, time()+31536000, "/", "somedomain");
令我困惑的是我们申请中的cookies。这可能会覆盖Yii会话存储配置吗?
更新
我也遇到过这行代码
$_SESSION['POLL_'.$idPoll.'somekey'] = strtotime("now");
这行代码在数据库中插入了会话记录。但该记录也有一年的寿命。这怎么可能?
答案 0 :(得分:0)
你需要像这样添加timeout param:
'session' => array(
'class' => 'CDbHttpSession',
'timeout' => 5256000,
// ...
答案 1 :(得分:0)
Try Cookies Like this : -
if (isset($_POST['remember'])) {
$cookieUsername = new CHttpCookie('phoenix_admin_username', $_POST['LoginForm']['username']);
$cookiePassword = new CHttpCookie('phoenix_admin_password', base64_encode($_POST['LoginForm']['password']));
$cookieUsername->expire = time() + 604800;
$cookiePassword->expire = time() + 604800;
Yii::app()->request->cookies['phoenix_admin_username'] = $cookieUsername;
Yii::app()->request->cookies['phoenix_admin_password'] = $cookiePassword;
}
////////////Check like this//////////////
if(isset(Yii::app()->request->cookies['phoenix_admin_username'])){
$model->username = Yii::app()->request->cookies['phoenix_admin_username']->value;
$model->password = base64_decode(Yii::app()->request->cookies['phoenix_admin_password']->value);
}else{
$model->username = "";
$model->password = "";
}