本文整理汇总了PHP中session_register_shutdown函数的典型用法代码示例。如果您正苦于以下问题:PHP session_register_shutdown函数的具体用法?PHP session_register_shutdown怎么用?PHP session_register_shutdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了session_register_shutdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
/**
* @return bool
*/
public static function start()
{
if (!self::$initialised) {
session_cache_limiter('');
ini_set('session.use_cookies', 1);
if (version_compare(phpversion(), '5.4.0', '>=')) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
self::$initialised = true;
}
if (session_status() === PHP_SESSION_DISABLED) {
Exception::error(Lib\I18n::__('PHP sessions are disabled.'));
}
if (session_status() === PHP_SESSION_ACTIVE) {
return true;
}
if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
Exception::error(Lib\I18n::__('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
}
if (!session_start()) {
Exception::error(Lib\I18n::__('Failed to start the session.'));
}
self::$reference =& $_SESSION;
return true;
}
示例2: bootstrap
/**
* 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();
}
示例3: __construct
/**
* 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);
}
示例4: __construct
/**
* Constructor
*
* @param KObjectConfig $config An optional ObjectConfig object with configuration options
*/
public function __construct(KObjectConfig $config)
{
parent::__construct($config);
//Session write and close handlers are called after destructing objects since PHP 5.0.5.
if (version_compare(phpversion(), '5.4.0', '>=')) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
//Only configure the session if it's not active yet
if (!$this->isActive()) {
//Set the session options
$this->setOptions($config->options);
//Set the session name
if (!empty($config->name)) {
$this->setName($config->name);
}
//Set the session identifier
if (!empty($config->id)) {
$this->setId($config->id);
}
//Set the session handler
$this->setHandler($config->handler, KObjectConfig::unbox($config));
}
//Set the session namespace
$this->setNamespace($config->namespace);
//Set lifetime time
$this->getContainer('metadata')->setLifetime($config->lifetime);
}
示例5: init
/**
* Constructor.
*
* @throws Session\SessionException
*/
protected function init()
{
$config = self::getConfig();
// validate that headers have not already been sent
if (headers_sent()) {
throw new SessionException('Unable to register session handler because headers have already been sent.');
}
// remove any shut down functions
session_register_shutdown();
// get the driver
$saveHandler = $config->get('Storage.Driver', '\\Webiny\\Component\\Http\\Session\\Storage\\NativeStorage');
try {
// try to create driver instance
$saveHandler = new $saveHandler($config);
// register driver as session handler
session_set_save_handler($saveHandler, false);
// start the session
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// get session id
$this->sessionId = session_id();
// save current session locally
$this->sessionBag = $this->arr($_SESSION);
} catch (\Exception $e) {
throw new SessionException($e->getMessage());
}
}
示例6: __invoke
public function __invoke(Request $req, Response $res, callable $next)
{
$config = $this->app['config'];
if (!$config->get('sessions.enabled') || $req->isApi()) {
return $next($req, $res);
}
$lifetime = $config->get('sessions.lifetime');
$hostname = $config->get('app.hostname');
ini_set('session.use_trans_sid', false);
ini_set('session.use_only_cookies', true);
ini_set('url_rewriter.tags', '');
ini_set('session.gc_maxlifetime', $lifetime);
// set the session name
$defaultSessionTitle = $config->get('app.title') . '-' . $hostname;
$sessionTitle = $config->get('sessions.name', $defaultSessionTitle);
$safeSessionTitle = str_replace(['.', ' ', "'", '"'], ['', '_', '', ''], $sessionTitle);
session_name($safeSessionTitle);
// set the session cookie parameters
session_set_cookie_params($lifetime, '/', '.' . $hostname, $req->isSecure(), true);
// register session_write_close as a shutdown function
session_register_shutdown();
// install any custom session handlers
$class = $config->get('sessions.driver');
if ($class) {
$handler = new $class($this->app);
$handler::registerHandler($handler);
}
session_start();
// fix the session cookie
Utility::setCookieFixDomain(session_name(), session_id(), time() + $lifetime, '/', $hostname, $req->isSecure(), true);
// make the newly started session in our request
$req->setSession($_SESSION);
return $next($req, $res);
}
示例7: __construct
/**
* @param \SessionHandlerInterface $handler
* @param string $namespace
*/
public function __construct(\SessionHandlerInterface $handler = null, $namespace = '__SLOTHS__')
{
if ($handler) {
session_set_save_handler($handler);
}
session_register_shutdown();
$this->namespace = $namespace;
}
示例8: __construct
/**
* Initialize the Session
*
* @param \SessionHandlerInterface $handler The session handler
*/
public function __construct(SessionHandlerInterface $handler = null, array $options = [])
{
session_register_shutdown();
$this->setOptions($options);
if (!$this->handler) {
$this->handler = $handler ?: new NativeHandler();
session_set_save_handler($this->handler, false);
}
}
示例9: start
/**
* Start a session
*
* @param array $config
*/
public static function start(array $config = array())
{
$default_config = array('use_cookies' => 1, 'name' => 'WT_SESSION', 'cookie_lifetime' => 0, 'gc_maxlifetime' => 7200, 'gc_probability' => 1, 'gc_divisor' => 100, 'cookie_path' => '', 'cookie_httponly' => true);
session_register_shutdown();
foreach ($config + $default_config as $key => $value) {
ini_set('session.' . $key, $value);
}
session_start();
}
示例10: __construct
/**
* Constructor
*
* @param \SessionHandlerInterface $handler Session save handler
* @param array $options Session options
*
* @since 1.0
*/
public function __construct(\SessionHandlerInterface $handler = null, array $options = array())
{
// Disable transparent sid support
ini_set('session.use_trans_sid', '0');
ini_set('session.use_cookies', 1);
session_cache_limiter('none');
session_register_shutdown();
$this->setOptions($options);
$this->setHandler($handler);
}
示例11: __construct
/**
* initialize storage mechanism, set save handler
*/
public function __construct()
{
ini_set('session.use_cookies', 1);
if (PHP_VERSION_ID >= 50400) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
$this->sessionDataBag = new SessionDataBag();
$this->setSaveHandler();
}
示例12: __construct
/**
* Construct
*
* @param array $options
* @param \SessionHandlerInterface $saveHandler
*/
public function __construct(array $options = array(), \SessionHandlerInterface $saveHandler = null)
{
session_cache_limiter('');
ini_set('session.use_cookies', 1);
ini_set('session.cookie_lifetime', 0);
$this->setOptions($options);
if ($saveHandler !== null) {
$this->setSaveHandler($saveHandler);
}
session_register_shutdown();
}
示例13: open
public function open($savePath, $sessionName)
{
if (function_exists('session_register_shutdown')) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
/* Nothing to do here. */
debug('session open');
return true;
}
示例14: Init
/**
* Инициализация модуля
*
*/
public function Init()
{
$this->bUseStandardSession = Config::Get('sys.session.standart');
// * Стартуем сессию
$this->Start();
if (!$this->GetCookie('visitor_id')) {
$this->SetCookie('visitor_id', F::RandomStr());
}
if (PHP_VERSION_ID >= 50400) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
}
示例15: __construct
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
ini_set('session.auto_start', 0);
ini_set('session.cache_limiter', '');
ini_set('session.use_cookies', 1);
if (version_compare(phpversion(), '5.4.0', '>=')) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
}
$this->setMetadataBag($metaBag);
$this->setOptions($options);
$this->setSaveHandler($handler);
}