请帮我理解,为什么 session 不写入数据库?
session 配置
'database' => array(
'name' => 'session_database',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => 'default',
'table' => 'sessions',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
我这样做:
Session::$default = 'database';
$this->session = Session::instance();
$this->session->set('test', 'test');
然后我重新加载页面,但在数据库的表 sessions
中没有看到新行
最佳答案
如果您使用加密,则需要确保已在 encrypt.php
配置文件中设置加密 key 。
'database' => array(
'name' => 'session_database',
'encrypted' => TRUE, /* using encryption requires a key */
)
/application/config/encrypt.php
<?php defined('SYSPATH') OR die('No direct script access.');
return array(
'default' => array(
/**
* The following options must be set:
*
* string key secret passphrase
* integer mode encryption mode, one of MCRYPT_MODE_*
* integer cipher encryption cipher, one of the Mcrpyt cipher constants
*/
'cipher' => MCRYPT_RIJNDAEL_128,
'mode' => MCRYPT_MODE_NOFB,
'key' => 'my_encryption_key'
),
);
关于database - Kohana 3.2 将 session 保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9406612/