How to get kohana session data outside kohana application?

余生长醉 提交于 2019-12-11 10:32:33

问题


I want to get the kohana session data outside the kohana application. I mean to say that i want to get the session data in a static file which is not a kohana page.


回答1:


I have tried many things and atlast i have found the answer,

In your controller class, get the native session id before kohana session instance and store it. Now close the native session and initiate kohana session by passing the session id as an argument.

    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);

Now you can access the session inside the kohana application.




回答2:


session_name('kohana'); //Your session name   
print_r($_SESSION);

You can apply configuration settings to each of the session adapters by creating a session config file at APPPATH/config/session.php. The following sample configuration file defines all the settings for each adapter:

[!!] As with cookies, a "lifetime" setting of "0" means that the session will expire when the browser is closed.

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,
    ),
);


来源:https://stackoverflow.com/questions/16623615/how-to-get-kohana-session-data-outside-kohana-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!