in reply to CGI Session not passing session info between pages

$session->flush(); at the end of login.pl helped me a lot.

Replies are listed 'Best First'.
Re^2: CGI Session not passing session info between pages
by bliako (Abbot) on Apr 02, 2018 at 09:49 UTC

    In the tutorial on CGI::Session there is the excerpt I paste at the end.

    What I understand from it is that at the end of your login script session should automatically be flush()ed, close()d and destroyed.

    Why is flush() not happening then?

    CLOSING THE SESSION
    
    Normally you don't have to close the session explicitly. It gets closed when your program terminates or session object goes out of scope. However in some few instances you might want to close the session explicitly by calling CGI::Session's close() method or undefining the object. What is closing all about - you'd ask. While session is active, updates to session object doesn't get stored in the disk right away. It stores them in the memory until you either choose to flush the buffer by calling flush() method or destroy the session object by either terminating the program or calling close() method explicitly.
    
    In some circumstances you might want to close the session but at the same time don't want to terminate the process for a while. Might be the case with GUI and in daemon applications. In this case close() is what you want. Note: we prefer simpl undefing the session rather than calling close() method. close() is less efficient):
    
        undef($session);
    
    If you want to keep the session object but for any reason want to synchronize the data in the buffer with the one in the disk, flush() method is what you need.
    
    Note: close() calls flush() as well. So there's no need to call flush() before calling close()
      Why is flush() not happening then?

      This puzzled me for some time. What I found was that if you replaced the init subroutine (with inline code) the OP code works. I think the reason is the order in which the session and dbh object are destroyed. With $session in the sub, the dbh is destroyed first preventing the data from being synchronized.

      poj