TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Kohana 3.3: Session data are not written on shutdown
  • Hello,

    I found, that Sessions were not working properly - they did not work at all...

    I made this simplified example to be able to discover the issue:

    public function action_index() {
    
        echo Session::instance()->get('test');
            
        Session::instance()->set('test', '12345');
    
        exit;
    }
    

    but there is nothing returned by echo Session::instance()->get('test');

    I am sure, there is called method _write() by Kohana_Session_Native on shutdown:

    
        /**
         * @return  bool
         */
        protected function _write()
        {
            // Write and close the session
            session_write_close();
    
            return TRUE;
        }
    

    Thank you for any advice!

  • Hey @AndyBrandy!

    What happens when you remove that exit at the end of the action_index?

  • Hello @enov,

    without any change.. Session does not return anything..

  • @AndyBrandy,

    without any change.. Session does not return anything..

    Are you sure you requested that action twice? For the first time it should not return anything. Only for the second time it should work.

    Also just for reference, I will link here the argument I made in your previous post:

    http://forum.kohanaframework.org/discussion/comment/80119#Comment_80119

  • Yes @enov, I request the action twice and the previous discussion does not solve the problem, thats why I have started this discussion..

  • hmm... :(

    I did a quick test and it's working for me...

    I hope you are not messing with native session functions in your index.php or bootstrap.php or anywhere else...

  • I do not think so.. I just can not find what could be wrong.. Session::write is called. When I dump _data there, test data are in.. But they are not written to the SESSION :-/

  • @enov,

    I am wondering, how the _data are written to $_SESSION. There is only function named session_write_close(); but nothing more..

  • There is also something interesting: when I want to print_r($_SESSION);, the error is printed:

    ErrorException [ Notice ]: Undefined variable: _SESSION
    

    it looks like session is not started...

  • When I set Session::$default to something other then 'native' (I tried 'cookie') I get the same error. So $this->response->body(Debug::vars(Session::$default)); to see if that is the case.

  • Hello @Darsstar, the output is string(6) "native"

  • I think I have found the bug.. I made my class Kohana_Session, where I added on line 298 this two lines:

            if($id === NULL)
                return FALSE;
    

    I do not know, why I did it, but maybe there was some error reporting... Anyways, now it works correctly...

  • That sounds like a terrible 'fix'.

    If you phpinfo(), what value does session.auto_start have? I remember an issue that got solved by changing the session_start(); line (43) in Kohana_Session_Native to ini_get('session.auto_start') OR session_start();. (An if would also work of course.)

    session_start() is located in Kohana_Session_Native::_read(). $this->_read($id) gets called on (the original) line 300 inside Kohana_Session, which you skip by returning FALSE.

  • I would call it 'quick terrible fix' also :) I really do not know, why I did it, because it was really long time ago..

  • Do you mind making a screenshot of the 'Session' portion of phpinfo()'s output? I am curious and currently bored :p

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion