Search code examples
phpsessionkohana-3.2

How to get kohana session data outside kohana application?


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.


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.