/** * Sets the time against which the session is measured. This function also * sets the cash_session_id internally as a mechanism for tracking analytics * against a consistent id, regardless of PHP session id. * * @return boolean */ protected function startSession() { // begin PHP session if (!defined('STDIN')) { // no session for CLI, suckers @session_cache_limiter('nocache'); $session_length = 3600; @ini_set("session.gc_maxlifetime", $session_length); @session_start(); } $this->cash_session_timeout = ini_get("session.gc_maxlifetime"); if (!isset($_SESSION['cash_session_id'])) { $modifier_array = array('deedee', 'johnny', 'joey', 'tommy', 'marky'); $_SESSION['cash_session_id'] = $modifier_array[array_rand($modifier_array)] . '_' . rand(1000, 9999) . substr((string) time(), 4); } if (isset($_SESSION['cash_last_request_time'])) { if ($_SESSION['cash_last_request_time'] + $this->cash_session_timeout < time()) { $this->resetSession(); } } $_SESSION['cash_last_request_time'] = time(); if (!isset($GLOBALS['cash_script_store'])) { $GLOBALS['cash_script_store'] = array(); } return true; }
function init() { ini_set('session.cookie_lifetime', 60 * 60 * 24 * 30); // Persistent cookies ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 30); // Garbage collection to match ini_set('session.cookie_httponly', true); // Restrict cookies to HTTP only (help reduce XSS attack profile) site()->db()->handleSession(); session_name(site()->config->sessionname); session_start(); session_cache_limiter('public'); session_regenerate_id(); // Session login / logout site()->addPageHandler('/session/login', '\\Idno\\Pages\\Session\\Login', true); site()->addPageHandler('/session/logout', '\\Idno\\Pages\\Session\\Logout'); site()->addPageHandler('/currentUser/?', '\\Idno\\Pages\\Session\\CurrentUser'); // Update the session on save, this is a shim until #46 is fixed properly with #49 \Idno\Core\site()->addEventHook('save', function (\Idno\Core\Event $event) { $object = $event->data()['object']; if (!empty($object) && $object instanceof \Idno\Entities\User && (!empty($_SESSION['user']) && $object->getUUID() == $_SESSION['user']->getUUID())) { $_SESSION['user'] = $object; } }); }
/** * Ethna_Sessionクラスのコンストラクタ * * @access public * @param string $appid アプリケーションID(セッション名として使用) * @param string $save_dir セッションデータを保存するディレクトリ */ public function __construct($ctl, $appid) { $this->ctl = $ctl; $this->logger = $this->ctl->getLogger(); $config = $this->ctl->getConfig()->get('session'); if ($config) { $this->config = array_merge($this->config, $config); } $this->session_save_dir = $this->config['path']; if (($dir = $this->ctl->getDirectory($this->config['path'])) !== null) { $this->session_save_dir = $dir; } $this->session_name = $appid . $this->config['suffix']; // set session handler ini_set('session.save_handler', $this->config['handler']); session_save_path($this->session_save_dir); session_name($this->session_name); session_cache_limiter($this->config['cache_limiter']); session_cache_expire($this->config['cache_expire']); $this->session_start = false; if (isset($_SERVER['REQUEST_METHOD']) == false) { return; } if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) { $http_vars = $_POST; } else { $http_vars = $_GET; } if (array_key_exists($this->session_name, $http_vars) && $http_vars[$this->session_name] != null) { $_COOKIE[$this->session_name] = $http_vars[$this->session_name]; } }
/** * セッションを開始する * @param string $name * @return $this * */ public function __construct($name = 'sess') { $this->ses_n = $name; if ('' === session_id()) { $cookie_params = \ebi\Conf::cookie_params(); session_name($cookie_params['session_name']); session_cache_expire($cookie_params['session_expire']); session_cache_limiter($cookie_params['session_limiter']); if ($cookie_params['cookie_lifetime'] > 0 || $cookie_params['cookie_path'] != '/' || !empty($cookie_params['cookie_domain']) || $cookie_params['cookie_secure'] !== false) { session_set_cookie_params($cookie_params['cookie_lifetime'], $cookie_params['cookie_path'], $cookie_params['cookie_domain'], $cookie_params['cookie_secure']); } if (static::has_class_plugin('session_read')) { ini_set('session.save_handler', 'user'); session_set_save_handler([$this, 'open'], [$this, 'close'], [$this, 'read'], [$this, 'write'], [$this, 'destroy'], [$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 __construct($config) { if (!is_object($config)) { require_once 'Oops/Config.php'; $config = new Oops_Config(); } if (strlen($config->domain) && strpos($_SERVER['HTTP_HOST'], (string) $config->domain) !== false) { $this->_cookieDomain = $config->domain; } if (strlen($config->path)) { $this->_cookiePath = $config->path; } if (strlen($config->lifetime)) { $this->_cookieLifetime = $config->lifetime; } session_set_cookie_params($this->_cookieLifetime, $this->_cookiePath, $this->_cookieDomain); if (strlen($config->name)) { session_name($config->name); } if (strlen($config->cache_limiter)) { session_cache_limiter($config->cache_limiter); } else { session_cache_limiter('nocache'); } }
/** * コンストラクタ * * ここでPHPの標準セッションがスタートする */ public function __construct($session_name = null, $session_id = null, $use_cookies = true) { $this->setCookieHttpOnly(); // キャッシュ制御なし session_cache_limiter('none'); // セッション名およびセッションIDを設定 if ($session_name) { session_name($session_name); } if ($session_id) { session_id($session_id); } // Cookie使用の可否に応じてiniディレクティブを変更 if ($use_cookies) { ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); } else { ini_set('session.use_cookies', 0); ini_set('session.use_only_cookies', 0); } // セッションデータを初期化する session_start(); self::$_session_started = true; // Cookieが使用できず、session.use_trans_sidがOffの場合 if (!$use_cookies && !ini_get('session.use_trans_sid')) { $snm = session_name(); $sid = session_id(); output_add_rewrite_var($snm, $sid); } /* Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache */ }
function ensure_session() { if (session_id() !== "") { return true; } if (!($sn = make_session_name(opt("sessionName")))) { return false; } // maybe upgrade from an old session name to this one if (!isset($_COOKIE[$sn]) && ($upgrade_sn = opt("sessionUpgrade")) && ($upgrade_sn = make_session_name($upgrade_sn)) && isset($_COOKIE[$upgrade_sn])) { session_id($_COOKIE[$upgrade_sn]); setcookie($upgrade_sn, "", time() - 3600, "/", opt("sessionUpgradeDomain", opt("sessionDomain", "")), opt("sessionSecure", false)); } $secure = opt("sessionSecure"); $domain = opt("sessionDomain"); if ($secure !== null || $domain !== null) { $params = session_get_cookie_params(); if ($secure !== null) { $params["secure"] = !!$secure; } if ($domain !== null) { $params["domain"] = $domain; } session_set_cookie_params($params["lifetime"], $params["path"], $params["domain"], $params["secure"]); } session_name($sn); session_cache_limiter(""); if (isset($_COOKIE[$sn]) && !preg_match(';\\A[-a-zA-Z0-9,]{1,128}\\z;', $_COOKIE[$sn])) { error_log("unexpected session ID <" . $_COOKIE[$sn] . ">"); unset($_COOKIE[$sn]); } session_start(); return true; }
function PbSessions($save_path = '') { global $_PB_CACHE; $iniSet = function_exists('ini_set'); $this->save_path = $save_path; if (empty($_SESSION)) { if ($iniSet && !empty($_PB_CACHE['setting']['session_savepath'])) { if (isset($_SERVER['HTTPS'])) { ini_set('session.cookie_secure', 1); } //Todo: //ini_set('session.use_cookies', 1); //ini_set('session.cookie_lifetime', $this->lifetime); if (!empty($this->save_path)) { ini_set('session.save_path', $this->save_path); } elseif (defined("DATA_PATH")) { session_save_path(DATA_PATH . "tmp" . DS); } } } if (headers_sent()) { if (empty($_SESSION)) { $_SESSION = array(); } return false; } elseif (!isset($_SESSION)) { session_cache_limiter("must-revalidate"); session_start(); header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); return true; } else { session_start(); return true; } }
/** * Available options: * * * session_name: The cookie name (symfony by default) * * session_id: The session id (null by default) * * auto_start: Whether to start the session (true by default) * * session_cookie_lifetime: Cookie lifetime * * session_cookie_path: Cookie path * * session_cookie_domain: Cookie domain * * session_cookie_secure: Cookie secure * * session_cookie_httponly: Cookie http only (only for PHP >= 5.2) * * The default values for all 'session_cookie_*' options are those returned by the session_get_cookie_params() function * * @param array $options An associative array of options * * @see sfStorage */ public function initialize($options = null) { $cookieDefaults = session_get_cookie_params(); $options = array_merge(array('session_name' => 'symfony', 'session_id' => null, 'auto_start' => true, 'session_cookie_lifetime' => $cookieDefaults['lifetime'], 'session_cookie_path' => $cookieDefaults['path'], 'session_cookie_domain' => $cookieDefaults['domain'], 'session_cookie_secure' => $cookieDefaults['secure'], 'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false, 'session_cache_limiter' => 'none'), $options); // initialize parent parent::initialize($options); // set session name $sessionName = $this->options['session_name']; session_name($sessionName); if (!(bool) ini_get('session.use_cookies') && ($sessionId = $this->options['session_id'])) { session_id($sessionId); } $lifetime = $this->options['session_cookie_lifetime']; $path = $this->options['session_cookie_path']; $domain = $this->options['session_cookie_domain']; $secure = $this->options['session_cookie_secure']; $httpOnly = $this->options['session_cookie_httponly']; session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly); if (!is_null($this->options['session_cache_limiter'])) { session_cache_limiter($this->options['session_cache_limiter']); } if ($this->options['auto_start'] && !self::$sessionStarted) { session_start(); self::$sessionStarted = true; } }
/** * Starts the session. * * @api */ public function start() { if (self::$sessionStarted) { return; } session_set_cookie_params( $this->options['lifetime'], $this->options['path'], $this->options['domain'], $this->options['secure'], $this->options['httponly'] ); // disable native cache limiter as this is managed by HeaderBag directly session_cache_limiter(false); if (!ini_get('session.use_cookies') && isset($this->options['id']) && $this->options['id'] && $this->options['id'] != session_id()) { session_id($this->options['id']); } session_start(); self::$sessionStarted = true; }
function forum_session_start() { static $forum_session_started = FALSE; $return = ($hook = get_hook('fn_forum_session_start_start')) ? eval($hook) : null; if ($return != null) { return; } // Check if session already started if ($forum_session_started && session_id()) { return; } session_cache_limiter(FALSE); // Check session id $forum_session_id = NULL; if (isset($_COOKIE['PHPSESSID'])) { $forum_session_id = $_COOKIE['PHPSESSID']; } else { if (isset($_GET['PHPSESSID'])) { $forum_session_id = $_GET['PHPSESSID']; } } if (empty($forum_session_id) || !preg_match('/^[a-z0-9]{16,32}$/', $forum_session_id)) { // Create new session id $forum_session_id = random_key(32, FALSE, TRUE); session_id($forum_session_id); } session_start(); if (!isset($_SESSION['initiated'])) { session_regenerate_id(); $_SESSION['initiated'] = TRUE; } $forum_session_started = TRUE; }
/** * starts new clean output buffer * * @access public * * @author patrick.kracht */ public function clean_ob() { if (!ob_get_length() || !ob_get_level()) { ob_start(); } session_cache_limiter('must-revalidate'); }
/** * Set up application environment * * This sets up the PHP environment, loads the provided module and returns * the MVC application. * * @param string $module Module to load * @param bool $addTestConfig Add config for test environment (enable all debug options, no config file) * @param array $applicationConfig Extends default application config * @return \Zend\Mvc\Application * @codeCoverageIgnore */ public static function init($module, $addTestConfig = false, $applicationConfig = array()) { // Set up PHP environment. session_cache_limiter('nocache'); // Default headers to prevent caching return \Zend\Mvc\Application::init(array_replace_recursive(static::getApplicationConfig($module, $addTestConfig), $applicationConfig)); }
/** * 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 function startSession() { if (session_status() !== PHP_SESSION_ACTIVE) { session_cache_limiter(false); session_start(); } }
/** startInit() initiates the environment * @return void */ public static function startInit() { @set_time_limit(0); @error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE); @ini_set('session.save_handler', 'mm'); @ini_set('session.cookie_httponly', true); @ob_start('sanitize_output'); @session_start(); @session_cache_limiter('no-cache'); @session_set_cookie_params(0, null, null, true, true); @set_magic_quotes_runtime(0); self::verCheck(); self::extCheck(); foreach ($_REQUEST as $key => $val) { $_REQUEST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING); } foreach ($_GET as $key => $val) { $_GET[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING); } foreach ($_POST as $key => $val) { $_POST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING); } foreach (array('node', 'sub', 'printertype', 'id', 'sub', 'crit', 'sort', 'confirm', 'tab') as $x) { global ${$x}; ${$x} = isset($_REQUEST[$x]) ? filter_var($_REQUEST[$x], FILTER_SANITIZE_STRING) : ''; } unset($x); new System(); new Config(); }
/** * @covers think\Session::init * * @todo Implement testInit(). */ public function testInit() { \think\Session::prefix(null); $config = ['prefix' => 'think_', 'expire' => 60, 'path' => '/path/to/test/session/', 'domain' => '.thinkphp.cn', 'var_session_id' => 'sessionidtest', 'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1', 'name' => 'session_name', 'use_trans_sid' => '1', 'use_cookies' => '1', 'cache_limiter' => '60', 'cache_expire' => '60', 'type' => '', 'namespace' => '\\think\\session\\driver\\', 'auto_start' => '1']; $_REQUEST[$config['var_session_id']] = $config['id']; \think\Session::init($config); // 开始断言 $this->assertEquals($config['prefix'], \think\Session::prefix()); $this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]); $this->assertEquals($config['name'], session_name()); $this->assertEquals($config['path'], session_save_path()); $this->assertEquals($config['use_cookies'], ini_get('session.use_cookies')); $this->assertEquals($config['domain'], ini_get('session.cookie_domain')); $this->assertEquals($config['expire'], ini_get('session.gc_maxlifetime')); $this->assertEquals($config['expire'], ini_get('session.cookie_lifetime')); $this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter'])); $this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire'])); // 检测分支 $_REQUEST[$config['var_session_id']] = null; session_write_close(); session_destroy(); \think\Session::init($config); // 测试auto_start // PHP_SESSION_DISABLED // PHP_SESSION_NONE // PHP_SESSION_ACTIVE // session_status() $this->assertEquals(0, ini_get('session.auto_start')); $this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid')); \think\Session::init($config); $this->assertEquals($config['id'], session_id()); }
public function __construct(Response $Response, LoggerInterface $Logger, $siteDomain, $sessionTtl, $sessionName, $sessionPersistSessions) { $this->Response = $Response; $this->Logger = $Logger; $this->siteDomain = $siteDomain; $this->sessionTTL = $sessionTtl; $this->sessionName = $sessionName; $this->sessionPersistSessions = $sessionPersistSessions; if (!empty($_SERVER['HTTP_HOST']) && !headers_sent()) { #We need to make sure session.gc_maxlifetime is close to the session TTL ini_set('session.gc_maxlifetime', $this->sessionTTL); session_name($this->sessionName); if (isset($_POST["PHPSESSID_FLASH"])) { session_id($_POST["PHPSESSID_FLASH"]); } session_set_cookie_params($this->sessionTTL, '/', $_SERVER['SERVER_NAME']); session_cache_limiter(FALSE); //session_cache_limiter('nocache'); //session_cache_expire(0); $this->session_start_nobadchars(); #If the session is already started, send a cookie extending the lifetime. if (!empty($_COOKIE[$this->sessionName]) && $this->sessionPersistSessions) { $this->Response->sendCookie($this->sessionName, session_id(), time() + 60 * 60 * 24 * 6000, '/', $_SERVER['SERVER_NAME'], false); } $this->flash = $this->getSessionAttribute(null, 'flash'); //$this->Logger->debug($this->flash); $this->removeSessionAttribute(null, 'flash'); //$this->Logger->debug('Cleared flash'); } }
/** * Default constructor. * * @access public * @param array $config */ public function __construct($config = array()) { // initialize the database $this->_init(empty($config) ? $this->_config : $config); // set object as the save handler session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); // set some important session vars ini_set('session.auto_start', 0); ini_set('session.gc_probability', 1); ini_set('session.gc_divisor', 100); ini_set('session.gc_maxlifetime', $this->_config['lifetime']); ini_set('session.referer_check', ''); ini_set('session.entropy_file', '/dev/urandom'); ini_set('session.entropy_length', 16); ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); ini_set('session.use_trans_sid', 0); ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character', 5); // disable client/proxy caching session_cache_limiter('nocache'); // set the cookie parameters session_set_cookie_params($this->_config['lifetime'], $this->_config['cookie_path'], $this->_config['cookie_domain']); // name the session session_name('mongo_sess'); // start it up session_start(); }
/** * @param int $lifetime Defaults to 1800 seconds. * @param string $path Cookie path. * @throws \RuntimeException */ public function __construct($lifetime, $path) { // Session is a singleton. if (isset(self::$instance)) { throw new \RuntimeException("Session has already been initialized.", 500); } // Destroy any existing sessions started with session.auto_start if (session_id()) { session_unset(); session_destroy(); } // Disable transparent sid support ini_set('session.use_trans_sid', 0); // Only allow cookies ini_set('session.use_cookies', 1); session_name('msF9kJcW'); session_set_cookie_params($lifetime, $path); register_shutdown_function([$this, 'close']); session_cache_limiter('nocache'); if (isset($this->count)) { $this->count++; } else { $this->count = 1; } self::$instance = $this; }
public static function initialize() { // Set Redis as session handler ini_set('session.save_handler', 'redis'); ini_set('session.save_path', 'unix:///var/run/redis/redis.sock?persistent=1'); // Specify hash function used for session ids. Usually does not // work on FreeBSD unless hash functions are compiled into the binary // ini_set('session.hash_function', 'sha256'); ini_set('session.hash_bits_per_character', 5); ini_set('session.entropy_length', 512); // Set session lifetime in redis (8h) ini_set('session.gc_maxlifetime', 28800); // Set cookie lifetime on client ini_set('session.cookie_lifetime', 0); // do not expose Cookie value to JavaScript (enforced by browser) ini_set('session.cookie_httponly', 1); if (Config::get('https_only') === true) { // only send cookie over https ini_set('session.cookie_secure', 1); } // prevent caching by sending no-cache header session_cache_limiter('nocache'); // rename session session_name('SESSIONID'); }
public function __construct($handler = null) { session_cache_limiter(''); ini_set('session.use_cookies', 1); $this->setMetadataBag(null); $this->setSaveHandler($handler); }
/** * Set PHP session settings * * @return bool */ public static function init() { if (self::$iniSet === true) { return false; } self::$iniSet = true; ini_set('session.use_cookies', '1'); ini_set('session.use_only_cookies', '1'); ini_set('session.use_trans_sid', 0); ini_set('session.auto_start', '0'); ini_set('session.serialize_handler', 'php'); ini_set('session.gc_maxlifetime', SESSION_LIFETIME); ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', '1000'); ini_set('session.bug_compat_warn', '0'); ini_set('session.bug_compat_42', '0'); ini_set('session.cookie_httponly', true); ini_set('session.save_path', CACHE_PATH . 'sessions'); ini_set('upload_tmp_dir', CACHE_PATH . 'sessions'); $HTTP_ROOT = MODE === 'INSTALL' ? dirname(HTTP_ROOT) : HTTP_ROOT; session_set_cookie_params(SESSION_LIFETIME, $HTTP_ROOT, NULL, HTTPS, true); session_cache_limiter('nocache'); session_name('2Moons'); return true; }
function TestPDFWriter() { session_cache_limiter("nocache"); $testpdf = new PDFWriter(); $testpdf->setOutputXML("C:/Sites/rpts/nccweb/rptreceipt.xml"); $testpdf->writePDF("rptr.pdf"); }
public static function __import__() { /** (none/nocache/private/private_no_expire/public) */ session_cache_limiter(Rhaco::def("core.Request@limiter", "nocache")); session_cache_expire(Rhaco::def("core.Request@expire", 2592000)); session_start(); }
/** * セッションを開始する * @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(); } }); } }
/** * Constructor. * * @param SessionHandlerInterface $handler */ public function __construct(SessionHandlerInterface $handler) { ini_set('session.use_cookies', 1); session_cache_limiter(''); session_register_shutdown(); $this->proxy = new SaveHandlerProxy($handler); }
public function init($options = null) { $cookie_defaults = session_get_cookie_params(); if (!isset($options['session_cookie_path']) && class_exists("waSystem")) { $options['session_cookie_path'] = waSystem::getInstance()->getRootUrl(); } $options = array_merge(array('session_id' => null, 'auto_start' => true, 'session_cookie_lifetime' => $cookie_defaults['lifetime'], 'session_cookie_path' => $cookie_defaults['path'], 'session_cookie_domain' => $cookie_defaults['domain'], 'session_cookie_secure' => $cookie_defaults['secure'], 'session_cookie_httponly' => true, 'session_cache_limiter' => 'none'), $options); // initialize parent parent::init($options); if (isset($this->options['session_name'])) { session_name($this->options['session_name']); } if (!(bool) ini_get('session.use_cookies') && ($session_id = $this->options['session_id'])) { session_id($session_id); } $lifetime = $this->options['session_cookie_lifetime']; $path = $this->options['session_cookie_path']; $domain = $this->options['session_cookie_domain']; $secure = $this->options['session_cookie_secure']; $http_only = $this->options['session_cookie_httponly']; session_set_cookie_params($lifetime, $path, $domain, $secure, $http_only); if (null !== $this->options['session_cache_limiter']) { session_cache_limiter($this->options['session_cache_limiter']); } if ($this->options['auto_start']) { if (isset($_COOKIE[session_name()])) { $this->open(); } } }
/** * Processes the search form and gets the array of resturant from the model which is passed to the view 'search' allon with the message and search string * @search_string * @return null */ public function search($search_string = "") { // support back press to search page header('Cache-Control: no cache'); session_cache_limiter('private_no_expire'); //session_start(); if (filter_input(INPUT_POST, "submit") == "Find Restaurant") { $search_string = filter_input(INPUT_POST, "search"); $_SESSION['search'] = $search_string; } elseif (isset($_SESSION['search'])) { $search_string = $_SESSION['search']; } else { $search_string = ""; } $result = $this->restaurant->search_restaurant($search_string); if (count($result) === 0) { //if result of search is zero give all resturants with a message $result = $this->restaurant->get_restaurants(); $message = "No result for '" . $search_string . "'. These are some restaurants we suggest:"; } else { // get the count of the result and create a message : Your search returned n results $message = "Your search returned " . count($result) . " results"; } $this->view('restaurant/search', array('name' => $result, 'message' => $message, 'search_string' => $search_string)); }
function __construct($config) { if (!$config || !is_array($config)) { $config["id"] = "PHPSESSID"; $config["path"] = "./data/session/"; $config["timeout"] = 3600; } $this->config($config); $sid = $config["id"] ? $config["id"] : "PHPSESSION"; session_name($sid); $this->sid = $sid; $session_id = isset($_POST[$sid]) ? $_POST[$sid] : (isset($_GET[$sid]) ? $_GET[$sid] : ""); if ($session_id && preg_match("/^[a-z0-9A-Z\\_\\-]+\$/u", $session_id)) { session_id($session_id); $this->sessid = $session_id; } else { $this->sessid = session_id(); } session_save_path($config["path"]); $this->config = $config; $this->timeout = $config["timeout"] ? $config["timeout"] : 600; session_cache_expire(intval($this->timeout) / 60); session_cache_limiter('public'); session_start(); }