session_set_save_handler( ): your own session handler : session_set_save_handler « Cookie Session « PHP






session_set_save_handler( ): your own session handler

 
Session open (called by session_start( ))

Session close (called at page end)

Session read (called after session_start( ) )

Session write (called when session data is to be written)

Session destroy (called by session_destroy( ) )

Session garbage collect (called randomly)

<?
    function sess_open($sess_path, $sess_name) {
            print "Session opened.\n";
            print "Sess_path: $sess_path\n";
            print "Sess_name: $sess_name\n\n";
            return true;
    }

    function sess_close( ) {
            print "Session closed.\n";
            return true;
    }

    function sess_read($sess_id) {
            print "Session read.\n";
            print "Sess_ID: $sess_id\n";
            return '';
    }

    function sess_write($sess_id, $data) {
            print "Session value written.\n";
            print "Sess_ID: $sess_id\n";
            print "Data: $data\n\n";
            return true;
    }

    function sess_destroy($sess_id) {
            print "Session destroy called.\n";
            return true;
    }

    function sess_gc($sess_maxlifetime) {
            print "Session garbage collection called.\n";
            print "Sess_maxlifetime: $sess_maxlifetime\n";
            return true;
    }

    session_set_save_handler("sess_open", "sess_close", "sess_read",
                    "sess_write", "sess_destroy", "sess_gc");
    session_start( );

    $_SESSION['foo'] = "bar";
    print "Some text\n";
    $_SESSION['baz'] = "wombat";
?>
  
  








Related examples in the same category