/** * @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; }