Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.57 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class SASSET_Session_database_driver extends CI_Session_database_driver
  5. {
  6.  
  7.     /**
  8.      * Session Write
  9.      *
  10.      * Execute the regular write(), then execute account_session_assoc(), which will see if
  11.      * this session already has an existing record in the account_sessions_assoc association
  12.      * table, if it does, just update the session_id, and +1 the regens value, if there is
  13.      * no existing record, then isnert one.
  14.      *
  15.      * @param    string $session_id   Current session ID of the viewer
  16.      * @param    string $session_data Base64encoded session data
  17.      *
  18.      * @return    boolean
  19.      * @access    public
  20.      * @since     0.1.0
  21.      */
  22.     public function write( $session_id, $session_data )
  23.     {
  24.         // If the Accounts model isnt loaded, load it
  25.         if( ! class_exists( 'Accounts_model', FALSE ) )
  26.         {
  27.             $CI =& get_instance();
  28.  
  29.             $CI->load->model( 'Accounts_model' );
  30.         }
  31.  
  32.         if( ! parent::write( $session_id, $session_data ) )
  33.         {
  34.             log_message( "error", "SESSION " . __METHOD__ . " - FAILED to write session data for session ID $session_id" );
  35.  
  36.             return FALSE;
  37.         }
  38.  
  39.         log_message( "error", "SESSION " . __METHOD__ . " - SUCCESSFULLY wrote session data for session ID $session_id" );
  40.  
  41.         // If theres an account ID set in the session data...
  42.         if( isset( $_SESSION['account_id'] ) )
  43.         {
  44.             log_message( 'error', "SESSION " . __METHOD__ . " - Associating session $session_id to account ID " . $_SESSION['account_id'] );
  45.             //log_message('error',"SESSION Writing session for account ID " . $_SESSION['account_id']);
  46.             // ... Associate the account ID to the session ID
  47.             //Accounts_model::$instance->assoc_session($_SESSION['account_id'], $session_id);
  48.             Accounts_model::account_session_assoc();
  49.         }
  50.         else
  51.         {
  52.             //log_message('error',"SESSION Writing session, but NO ACCOUNT ID FOUND");
  53.         }
  54.  
  55.         return TRUE;
  56.     }
  57.  
  58.     /**
  59.      * Garbage Collector
  60.      *
  61.      * Execute the regular gc(), then execute _assoc_gc(), which will delete any sessions from the
  62.      * aaccount_sessions_assoc association table if the session_id isnt found in ci_sessions
  63.      *
  64.      * @param    integer $maxlifetime Time stamp used to mark which sessions should be deleted
  65.      *
  66.      * @return    boolean
  67.      * @access    public
  68.      * @since     0.1.0
  69.      */
  70.     public function gc( $maxlifetime )
  71.     {
  72.         if( ! parent::gc( $maxlifetime ) )
  73.         {
  74.             log_message( 'error', "SESSION " . __METHOD__ . " - Garbage collector failed.." );
  75.  
  76.             return FALSE;
  77.         }
  78.  
  79.         log_message( 'error', "SESSION " . __METHOD__ . " - Executing assoc GC" );
  80.  
  81.         return $this->_assoc_gc();
  82.     }
  83.  
  84.     /**
  85.      * Session Destroy
  86.      *
  87.      * Execute the regular destroy(), then execute _assoc_gc(), which will delete any sessions from the
  88.      * account_sessions_assoc association table if the session_id isnt found in ci_sessions
  89.      *
  90.      * @param    string $session_id Session ID to destroy
  91.      *
  92.      * @return    boolean
  93.      * @access    public
  94.      * @since     0.1.0
  95.      */
  96.     public function destroy( $session_id )
  97.     {
  98.         if( ! parent::destroy( $session_id ) )
  99.         {
  100.             log_message( 'error', "SESSION " . __METHOD__ . " - Delete failed for session ID $session_id" );
  101.  
  102.             return FALSE;
  103.         }
  104.  
  105.         log_message( 'error', "SESSION " . __METHOD__ . " - Executing assoc GC" );
  106.  
  107.         return $this->_assoc_gc();
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement