database - Kohana 3.2 将 session 保存在数据库中

标签 database session kohana

请帮我理解,为什么 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/

相关文章:

php - 使用 Kohana ORM 查询 IN (2,3,4)

database - 如何跟踪、存储和遍历一个巨大的球形数据结构

security - 在多个设备上使用 token 和系列实现记住我

.net - 确定 session 中使用 ASP.NET 中的哪些对象

mysql - Kohana ORM,重写 ORDER BY 和 GROUP BY 查询

php - 根据数据库中的值选中复选框

php - 使用 PHP 在 mySQL 上存储信息

sql-server - Uniqueidentifier vs. IDENTITY vs. Material Code——哪个是主键的最佳选择?

c++ - 打开与 Qt/C++ 的数据库连接

c# - WCF 服务中跨 session 持续存在的静态变量