コード例 #1
0
 /**
  * @static
  * @param int $intDbIndex The index in the database array
  * @param string $strTableName The table name to be used for saving sessions.
  * @return boolean
  */
 public static function Initialize($intDbIndex = 1, $strTableName = "qc_session")
 {
     self::$intDbIndex = QType::Cast($intDbIndex, QType::Integer);
     self::$strTableName = QType::Cast($strTableName, QType::String);
     // If the database index exists
     if (!array_key_exists(self::$intDbIndex, QApplication::$Database)) {
         throw new QCallerException('No database defined at DB_CONNECTION index ' . self::$intDbIndex . '. Correct your settings in configuration.inc.php.');
     }
     $objDatabase = QApplication::$Database[self::$intDbIndex];
     // see if the database contains a table with desired name
     if (!in_array(self::$strTableName, $objDatabase->GetTables())) {
         throw new QCallerException('Table ' . self::$strTableName . ' not found in database at DB_CONNECTION index ' . self::$intDbIndex . '. Correct your settings in configuration.inc.php.');
     }
     // Set session handler functions
     $session_ok = session_set_save_handler('QDbBackedSessionHandler::SessionOpen', 'QDbBackedSessionHandler::SessionClose', 'QDbBackedSessionHandler::SessionRead', 'QDbBackedSessionHandler::SessionWrite', 'QDbBackedSessionHandler::SessionDestroy', 'QDbBackedSessionHandler::SessionGarbageCollect');
     // could not register the session handler functions
     if (!$session_ok) {
         throw new QCallerException("session_set_save_handler function failed");
     }
     // Will be called before session ends.
     register_shutdown_function('session_write_close');
     return $session_ok;
 }
コード例 #2
0
 public static function SessionOverride()
 {
     // Are we using QDbBackedSessionHandler?
     if (defined("DB_BACKED_SESSION_HANDLER_DB_INDEX") && constant("DB_BACKED_SESSION_HANDLER_DB_INDEX") != 0 && defined("DB_BACKED_SESSION_HANDLER_TABLE_NAME")) {
         // Yes we are going to override PHP's default file based handlers.
         QDbBackedSessionHandler::Initialize(DB_BACKED_SESSION_HANDLER_DB_INDEX, DB_BACKED_SESSION_HANDLER_TABLE_NAME);
     }
 }
コード例 #3
0
 /**
  * Open the session (used by PHP when the session handler is active)
  * @param string $save_path
  * @param string $session_name
  *
  * @return bool
  */
 public static function SessionOpen($save_path, $session_name)
 {
     self::$strSessionName = $session_name;
     // Nothing to do
     return true;
 }