function osTicketSession($ttl = 0) { $this->ttl = $ttl ?: ini_get('session.gc_maxlifetime') ?: SESSION_TTL; // Set osTicket specific session name. session_name('OSTSESSID'); // Forced cleanup on shutdown register_shutdown_function('session_write_close'); // Set session cleanup time to match TTL ini_set('session.gc_maxlifetime', $ttl); if (OsticketConfig::getDBVersion()) { return session_start(); } # Cookies // Avoid setting a cookie domain without a dot, thanks // http://stackoverflow.com/a/1188145 $domain = null; if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false && !Validator::is_ip($_SERVER['HTTP_HOST'])) { // Remote port specification, as it will make an invalid domain list($domain) = explode(':', $_SERVER['HTTP_HOST']); } session_set_cookie_params($ttl, ROOT_PATH, $domain, osTicket::is_https()); //Set handlers. session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); //Start the session. session_start(); }
function osTicketSession($ttl = 0) { $this->ttl = $ttl ?: ini_get('session.gc_maxlifetime') ?: SESSION_TTL; // Set osTicket specific session name. session_name('OSTSESSID'); // Forced cleanup on shutdown register_shutdown_function('session_write_close'); // Set session cleanup time to match TTL ini_set('session.gc_maxlifetime', $ttl); if (OsticketConfig::getDBVersion()) { return session_start(); } # Cookies // Avoid setting a cookie domain without a dot, thanks // http://stackoverflow.com/a/1188145 $domain = null; if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false && !Validator::is_ip($_SERVER['HTTP_HOST'])) { // Remote port specification, as it will make an invalid domain list($domain) = explode(':', $_SERVER['HTTP_HOST']); } session_set_cookie_params($ttl, ROOT_PATH, $domain, osTicket::is_https()); if (!defined('SESSION_BACKEND')) { define('SESSION_BACKEND', 'db'); } try { $bk = SESSION_BACKEND; if (!class_exists(self::$backends[$bk])) { $bk = 'db'; } $this->backend = new self::$backends[$bk]($this->ttl); } catch (Exception $x) { // Use the database for sessions trigger_error($x->getMessage(), E_USER_WARNING); $this->backend = new self::$backends['db']($this->ttl); } if ($this->backend instanceof SessionBackend) { // Set handlers. session_set_save_handler(array($this->backend, 'open'), array($this->backend, 'close'), array($this->backend, 'read'), array($this->backend, 'write'), array($this->backend, 'destroy'), array($this->backend, 'gc')); } // Start the session. session_start(); }