PHP Session et Cookies: Exemple de gestionnaire de session

Author:
 
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. ";
            print "Sess_path: $sess_path ";
            print "Sess_name: $sess_name ";
            return true;
    }
 
    function sess_close( ) {
            print "Session closed. ";
            return true;
    }
 
    function sess_read($sess_id) {
            print "Session read. ";
            print "Sess_ID: $sess_id ";
            return '';
    }
 
    function sess_write($sess_id, $data) {
            print "Session value written. ";
            print "Sess_ID: $sess_id ";
            print "Data: $data ";
            return true;
    }
 
    function sess_destroy($sess_id) {
            print "Session destroy called. ";
            return true;
    }
 
    function sess_gc($sess_maxlifetime) {
            print "Session garbage collection called. ";
            print "Sess_maxlifetime: $sess_maxlifetime ";
            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 ";
    $_SESSION['baz'] = "wombat";
?>
  
  

Leave a Reply

Your email address will not be published. Required fields are marked *


× 8 = sixty four