Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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,
    ),
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top