1

我想在 kohana 应用程序之外获取 kohana 会话数据。我的意思是说我想在不是 kohana 页面的静态文件中获取会话数据。

4

2 回答 2

2

我尝试了很多事情,最后我找到了答案,

在您的控制器类中,在 kohana 会话实例之前获取本机会话 ID 并将其存储。现在关闭本机会话并通过将会话 ID 作为参数传递来启动 kohana 会话。

    session_start();    
    // Store session id and close the session
    $sessionId = session_id();
    session_write_close();

    // Then we can restore the session by using the session id 
    // and the Session class from Kohana
    Session::Instance(Session::$default, $sessionId);

现在您可以访问 kohana 应用程序中的会话。

于 2013-07-16T12:17:09.707 回答
1
session_name('kohana'); //Your session name   
print_r($_SESSION);

您可以通过在APPPATH/config/session.php. 以下示例配置文件定义了每个适配器的所有设置:

[!!] 与 cookie 一样,“生命周期”设置为“0”意味着会话将在浏览器关闭时过期。

return array(
    'native' => array(
        'name' => 'session_name',
        'lifetime' => 43200,
    ),
    'cookie' => array(
        'name' => 'cookie_name',
        'encrypted' => TRUE,
        'lifetime' => 43200,
    ),
    'database' => array(
        'name' => 'cookie_name',
        'encrypted' => TRUE,
        'lifetime' => 43200,
        'group' => 'default',
        'table' => 'table_name',
        'columns' => array(
            'session_id'  => 'session_id',
            'last_active' => 'last_active',
            'contents'    => 'contents'
        ),
        'gc' => 500,
    ),
);
于 2013-05-18T11:26:20.903 回答