function xoonips_session_regenerate() { $old_sessid = session_id(); session_regenerate_id(); $new_sessid = session_id(); session_id($old_sessid); session_destroy(); $old_session = $_SESSION; session_id($new_sessid); $sess_handler =& xoops_gethandler('session'); session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc')); session_start(); $_SESSION = array(); foreach (array_keys($old_session) as $key) { $_SESSION[$key] = $old_session[$key]; } // write and close session for xnp_is_valid_session_id() session_write_close(); // restart session session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc')); session_start(); $_SESSION = array(); foreach (array_keys($old_session) as $key) { $_SESSION[$key] = $old_session[$key]; } }
public static function start($lifetime = 0, $path = '/', $domain = NULL) { if (!self::$_initialized) { if (!is_object(Symphony::Database()) || !Symphony::Database()->connected()) { return false; } $cache = Cache::instance()->read('_session_config'); if (is_null($cache) || $cache === false) { self::create(); Cache::instance()->write('_session_config', true); } if (!session_id()) { ini_set('session.save_handler', 'user'); ini_set('session.gc_maxlifetime', $lifetime); ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', '3'); } session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc')); session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false); if (strlen(session_id()) == 0) { if (headers_sent()) { throw new Exception('Headers already sent. Cannot start session.'); } session_start(); } self::$_initialized = true; } return session_id(); }
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(); }
public static function start($lifetime = 0, $path = '/', $domain = NULL) { if (!self::$_initialized) { if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) { return false; } self::$_cache = new Cacheable(Symphony::Database()); $installed = self::$_cache->check('_session_config'); if (!$installed) { if (!self::createTable()) { return false; } self::$_cache->write('_session_config', true); } ini_set('session.save_handler', 'user'); ini_set('session.gc_maxlifetime', $lifetime); session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc')); session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false); if (strlen(session_id()) == 0) { if (headers_sent()) { throw new Exception('Headers already sent. Cannot start session.'); } session_start(); } self::$_initialized = true; } return session_id(); }
/** * 构造函数 * */ public function __construct() { $this->db = pc_base::load_model('session_model'); $this->lifetime = pc_base::load_config('system', 'session_ttl'); session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); session_start(); }
public static function Init() { if (CSecuritySessionVirtual::isStorageEnabled()) { if (!CSecuritySessionVirtual::init()) { self::triggerFatalError("Failed to initialize Virtual session handler"); } //may return false with session.auto_start is set to On if (session_set_save_handler(array("CSecuritySessionVirtual", "open"), array("CSecuritySessionVirtual", "close"), array("CSecuritySessionVirtual", "read"), array("CSecuritySessionVirtual", "write"), array("CSecuritySessionVirtual", "destroy"), array("CSecuritySessionVirtual", "gc"))) { register_shutdown_function("session_write_close"); } } elseif (CSecuritySessionMC::isStorageEnabled()) { if (!CSecuritySessionMC::Init()) { self::triggerFatalError("Failed to initialize Memcache session handler"); } //may return false with session.auto_start is set to On if (session_set_save_handler(array("CSecuritySessionMC", "open"), array("CSecuritySessionMC", "close"), array("CSecuritySessionMC", "read"), array("CSecuritySessionMC", "write"), array("CSecuritySessionMC", "destroy"), array("CSecuritySessionMC", "gc"))) { register_shutdown_function("session_write_close"); } } else { if (!CSecuritySessionDB::Init()) { self::triggerFatalError("Failed to initialize DB session handler"); } //may return false with session.auto_start is set to On if (session_set_save_handler(array("CSecuritySessionDB", "open"), array("CSecuritySessionDB", "close"), array("CSecuritySessionDB", "read"), array("CSecuritySessionDB", "write"), array("CSecuritySessionDB", "destroy"), array("CSecuritySessionDB", "gc"))) { register_shutdown_function("session_write_close"); } } }
public function __construct($conn, $tabela) { self::$_conn = $conn; self::$_table = $tabela; session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); register_shutdown_function('session_write_close'); }
/** * Default constructor */ public function __construct($db, $config) { $this->db = $db; $this->start = microtime(true); $this->ip = rcube_utils::remote_addr(); $this->logging = $config->get('log_session', false); $lifetime = $config->get('session_lifetime', 1) * 60; $this->set_lifetime($lifetime); // use memcache backend $this->storage = $config->get('session_storage', 'db'); if ($this->storage == 'memcache') { $this->memcache = rcube::get_instance()->get_memcache(); // set custom functions for PHP session management if memcache is available if ($this->memcache) { ini_set('session.serialize_handler', 'php'); session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'mc_read'), array($this, 'mc_write'), array($this, 'mc_destroy'), array($this, 'gc')); } else { rcube::raise_error(array('code' => 604, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Failed to connect to memcached. Please check configuration"), true, true); } } else { if ($this->storage != 'php') { ini_set('session.serialize_handler', 'php'); // set custom functions for PHP session management session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'db_read'), array($this, 'db_write'), array($this, 'db_destroy'), array($this, 'gc')); $this->table_name = $this->db->table_name('session', true); } } }
/** * Constructor */ public function __construct() { session_set_save_handler(array($this, "open"), array($this, "close"), array($this, "read"), array($this, "write"), array($this, "destroy"), array($this, "gc")); if (!extension_loaded('mcrypt')) { throw new Exception("The SecureSession class needs the Mcrypt PHP extension, please install it."); } }
/** * Starts a Session object, only if one doesn't already exist. This function maps * the Session Handler functions to this classes methods by reading the default * information from the PHP ini file. * * @link http://php.net/manual/en/function.session-set-save-handler.php * @link http://php.net/manual/en/function.session-set-cookie-params.php * @param integer $lifetime * How long a Session is valid for, by default this is 0, which means it * never expires * @param string $path * The path the cookie is valid for on the domain * @param string $domain * The domain this cookie is valid for * @param boolean $httpOnly * Whether this cookie can be read by Javascript. By default the cookie * cannot be read by Javascript * @param boolean $secure * Whether this cookie should only be sent on secure servers. By default this is * false, which means the cookie can be sent over HTTP and HTTPS * @throws Exception * @return string|boolean * Returns the Session ID on success, or false on error. */ public static function start($lifetime = 0, $path = '/', $domain = null, $httpOnly = true, $secure = false) { if (!self::$_initialized) { if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) { return false; } if (session_id() == '') { ini_set('session.save_handler', 'user'); ini_set('session.gc_maxlifetime', $lifetime); ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', Symphony::Configuration()->get('session_gc_divisor', 'symphony')); } session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc')); session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), $secure, $httpOnly); session_cache_limiter(''); if (session_id() == '') { if (headers_sent()) { throw new Exception('Headers already sent. Cannot start session.'); } register_shutdown_function('session_write_close'); session_start(); } self::$_initialized = true; } return session_id(); }
public static function init() { session::$db = db::get(true); if (!ini_get('session.gc_probability')) { @ini_set('session.gc_probability', 1); } if (!ini_get('session.gc_divisor')) { @ini_set('session.gc_divisor', 100); } session_set_save_handler(array('session', 'open'), array('session', 'close'), array('session', 'read'), array('session', 'write'), array('session', 'destroy'), array('session', 'gc')); $hash = null; session_name('sess_hash'); if (!html_get_cookie('sess_hash')) { if ($hash = session::restore()) { session_id($hash); } else { html_set_cookie('user_logon', '', time() - YEAR_IN_SECONDS); html_set_cookie('user_token', '', time() - YEAR_IN_SECONDS); } } session_start(); if (!isset($_SESSION['UID'])) { $_SESSION['UID'] = 0; } if (!is_null($hash)) { session::refresh_csrf_token(); } }
public function __construct() { // 这里使用静态的调用方法不行了。必须传入一个对象 ini_set('session.save_handler', 'user'); session_set_save_handler(array($this, 'sess_open'), array($this, 'sess_close'), array($this, 'sess_read'), array($this, 'sess_write'), array($this, 'sess_destroy'), array($this, 'sess_gc')); @session_start(); }
public function __construct(array $options = array()) { $this->setMetadataBag(); // create IP finger print $current_ipaddr = ''; $_REMOTE_ADDR = System::serverGetVar('REMOTE_ADDR'); $_HTTP_X_FORWARDED_FOR = System::serverGetVar('HTTP_X_FORWARDED_FOR'); if (System::getVar('sessionipcheck')) { // feature for future release } // create the ip fingerprint $current_ipaddr = md5($_REMOTE_ADDR . $_HTTP_X_FORWARDED_FOR); $this->object = array('lastused' => date('Y-m-d H:i:s', time()), 'uid' => 0, 'ipaddr' => $current_ipaddr, 'remember' => 0, 'vars' => ''); $path = System::getBaseUri(); if (empty($path)) { $path = '/'; } elseif (substr($path, -1, 1) != '/') { $path .= '/'; } $options = array_merge(array('auto_start' => 0, 'use_cookies' => 1, 'gc_probability' => System::getVar('gc_probability'), 'gc_divisor' => 10000, 'gc_maxlifetime' => System::getVar('secinactivemins') * 60, 'hash_function' => 1, 'cookie_path' => $path), $options); $this->setOptions($options); session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); register_shutdown_function('session_write_close'); $this->saveHandler = new SessionHandlerProxy($this); }
public function __construct($config) { $this->sessionDbName = $config['storageName']; $this->sessionDbConn = new Resources\Database($config['driverConnection']); session_set_save_handler(array($this, 'sessionStart'), array($this, 'sessionEnd'), array($this, 'sessionRead'), array($this, 'sessionWrite'), array($this, 'sessionDestroy'), array($this, 'sessionGc')); parent::__construct($config); }
/** * Register session connection driver * * Registers the session connection driver as current session handler * * See {@link http://php.net/session_set_save_handler * session_set_save_handler()} for more details * * @return bool */ public function register() { if ($this->_registered !== true) { $this->_registered = @session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'clean')); } return $this->_registered; }
function __construct() { // set our custom session functions. session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); // This line prevents unexpected effects when using objects as save handlers. register_shutdown_function('session_write_close'); }
function __construct() { // set our custom session functions. session_set_save_handler(array($this, 'abrir'), array($this, 'cerrar'), array($this, 'leer'), array($this, 'escribir'), array($this, 'destruir'), array($this, 'gc')); // This line prevents unexpected effects when using objects as save handlers. register_shutdown_function('session_write_close'); }
/** * Bootstrap the session. * * @param Config $config The session config */ public static function bootstrap(Config $config) { if (!$config->cookie_name) { $config->cookie_name = 'session_id'; } if (!$config->id_format) { $config->id_format = Handler::DEFAULT_ID_FORMAT; } // Create and set the session save handler static::$handler = new Handler($config); session_set_save_handler(static::$handler, true); // Set the session name session_name($config->cookie_name); // Set the cookie parameters $app = Application::instance(); $path = $app->config->base_uri ?: '/'; $domain = $app->config->domain ?: $_SERVER['HTTP_HOST']; $secure = $app->request->isSecure(); $lifetime = $config->lifetime ?: 2592000; session_set_cookie_params($lifetime, $path, $domain, $secure, true); // Start the session session_start(); // Register session_write_close() as a shutdown function session_register_shutdown(); }
/** * Handle the session in Postgres */ function handleSession() { if (version_compare(phpversion(), '5.3', '>')) { $sessionHandler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler(\Idno\Core\Idno::site()->db()->getClient(), array('db_table' => 'session', 'db_id_col' => 'session_id', 'db_data_col' => 'session_value', 'db_time_col' => 'session_time')); session_set_save_handler($sessionHandler, true); } }
function setupSession($session, $savepath = 'storage/sessions') { ini_set('session.save_handler', 'files'); session_set_save_handler($session, true); session_save_path(config('base_path') . $savepath); ini_set('session.gc_probability', 1); }
public static function start() { $config = Registry::get('config'); if (isset($config->session)) { // optional parameters sent to the constructor if (isset($config->session->params)) { $sessionParams = $config->session->params; } if (is_object($config->session->handler)) { $sessionHandler = self::factory($config->session->handler->namespace, $config->session->handler->class, $sessionParams, $config->session->lifetime); } else { $sessionHandler = self::factory('Nf\\Session', $config->session->handler, $sessionParams, $config->session->lifetime); } session_name($config->session->cookie->name); session_set_cookie_params(0, $config->session->cookie->path, $config->session->cookie->domain, false, true); session_set_save_handler(array(&$sessionHandler, 'open'), array(&$sessionHandler, 'close'), array(&$sessionHandler, 'read'), array(&$sessionHandler, 'write'), array(&$sessionHandler, 'destroy'), array(&$sessionHandler, 'gc')); register_shutdown_function('session_write_close'); session_start(); // session_regenerate_id(true); Registry::set('session', $sessionHandler); return $sessionHandler; } else { return false; } }
public function __construct() { //调用父类的构造方法 parent::__construct(); //修改session机制 session_set_save_handler(array($this, 'sess_open'), array($this, 'sess_close'), array($this, 'sess_read'), array($this, 'sess_write'), array($this, 'sess_destroy'), array($this, 'sess_gc')); }
protected function setSessionHandler(\SessionHandlerInterface $sessionHandler = null) { if (!empty($sessionHandler)) { $this->sessionHandler = $sessionHandler; session_set_save_handler($sessionHandler); } }
/** * Set Session Module */ private function _setSessionModule() { session_module_name('user'); session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); register_shutdown_function('session_write_close'); session_start(); }
/** * セッションの初期化を行う. * */ public function initSession() { session_set_save_handler(array(&$this, 'sfSessOpen'), array(&$this, 'sfSessClose'), array(&$this, 'sfSessRead'), array(&$this, 'sfSessWrite'), array(&$this, 'sfSessDestroy'), array(&$this, 'sfSessGc')); // 通常よりも早い段階(オブジェクトが破棄される前)でセッションデータを書き込んでセッションを終了する // XXX APC による MDB2 の破棄タイミングによる不具合を回避する目的 register_shutdown_function('session_write_close'); }
/** * セッションを開始する * @param string $name * @return $this */ protected function __new__($name = 'sess') { $this->ses_n = $name; if ('' === session_id()) { $session_name = \org\rhaco\Conf::get('session_name', 'SID'); if (!ctype_alpha($session_name)) { throw new \InvalidArgumentException('session name is is not a alpha value'); } session_cache_limiter(\org\rhaco\Conf::get('session_limiter', 'nocache')); session_cache_expire((int) (\org\rhaco\Conf::get('session_expire', 10800) / 60)); session_name(); if (static::has_module('session_read')) { ini_set('session.save_handler', 'user'); session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); if (isset($this->vars[$session_name])) { session_regenerate_id(true); } } session_start(); register_shutdown_function(function () { if ('' != session_id()) { session_write_close(); } }); } }
public function run() { $options = C("SESSION_OPTIONS"); $this->memcache = new Memcache(); $this->memcache->connect($options['host'], $options['port'], 2.5); session_set_save_handler(array(&$this, "open"), array(&$this, "close"), array(&$this, "read"), array(&$this, "write"), array(&$this, "destroy"), array(&$this, "gc")); }
/** Session constructor. Sets this class as the session save handler to make php use it as its save method for saving php normal session. It also registers session_write_close() as the shutdown function to make sure that session is written before the page closes. And it starts session using session_start. so to implement session in any file just require_once this file. @access Public. */ function db_session() { $this->object(); session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); register_shutdown_function('session_write_close'); session_start(); }
/** * Constructor. Starts PHP session handling in our own private store * * Side-effect: might set a cookie, so must be called before any other output. */ public function __construct() { $this->typo3tempPath = PATH_site . 'typo3temp/'; // Start our PHP session early so that hasSession() works $sessionSavePath = $this->getSessionSavePath(); // Register our "save" session handler session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); session_save_path($sessionSavePath); session_name($this->cookieName); ini_set('session.cookie_path', GeneralUtility::getIndpEnv('TYPO3_SITE_PATH')); // Always call the garbage collector to clean up stale session files ini_set('session.gc_probability', 100); ini_set('session.gc_divisor', 100); ini_set('session.gc_maxlifetime', $this->expireTimeInMinutes * 2 * 60); if (\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSessionAutoStartEnabled()) { $sessionCreationError = 'Error: session.auto-start is enabled.<br />'; $sessionCreationError .= 'The PHP option session.auto-start is enabled. Disable this option in php.ini or .htaccess:<br />'; $sessionCreationError .= '<pre>php_value session.auto_start Off</pre>'; throw new \TYPO3\CMS\Install\Exception($sessionCreationError, 1294587485); } elseif (defined('SID')) { $sessionCreationError = 'Session already started by session_start().<br />'; $sessionCreationError .= 'Make sure no installed extension is starting a session in its ext_localconf.php or ext_tables.php.'; throw new \TYPO3\CMS\Install\Exception($sessionCreationError, 1294587486); } session_start(); }
static function start() { if (!org_glizy_Session::isStarted()) { $sessionStore = org_glizy_Config::get('glizy.session.store'); $prefix = org_glizy_Config::get('SESSION_PREFIX'); $timeout = org_glizy_Config::get('SESSION_TIMEOUT'); if ($sessionStore) { $storagePrefix = org_glizy_Config::get('glizy.session.store.prefix'); if (!$storagePrefix) { $storagePrefix = 'PHPSESSID'; } $store = org_glizy_ObjectFactory::createObject($sessionStore, $timeout, $storagePrefix . $prefix); if (!$store) { throw new Exception('Session Store don\'t exists: ' . $sessionStore); } session_set_save_handler($store); } if (!isset($_SESSION)) { org_glizy_Session::glz_session_start(); } if (isset($_SESSION[$prefix . 'sessionLastAction']) && time() - $_SESSION[$prefix . 'sessionLastAction'] > $timeout) { $_SESSION = array(); } $_SESSION[$prefix . 'sessionStarted'] = true; $_SESSION[$prefix . 'sessionLastAction'] = time(); } }