miniflux-legacy/vendor/PicoFarad/Session.php

76 lines
1.6 KiB
PHP
Raw Normal View History

2013-02-18 03:48:21 +01:00
<?php
namespace PicoFarad\Session;
2014-05-28 22:12:29 +02:00
const SESSION_LIFETIME = 0;
2013-02-18 03:48:21 +01:00
2014-02-08 20:13:14 +01:00
function open($base_path = '/', $save_path = '')
2013-02-18 03:48:21 +01:00
{
2014-02-08 20:13:14 +01:00
if ($save_path !== '') session_save_path($save_path);
// HttpOnly and secure flags for session cookie
session_set_cookie_params(
SESSION_LIFETIME,
$base_path ?: '/',
null,
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on',
true
);
// Avoid session id in the URL
ini_set('session.use_only_cookies', true);
// Ensure session ID integrity
ini_set('session.entropy_file', '/dev/urandom');
ini_set('session.entropy_length', '32');
ini_set('session.hash_bits_per_character', 6);
// Custom session name
session_name('__$');
2013-02-18 03:48:21 +01:00
session_start();
// Regenerate the session id to avoid session fixation issue
if (empty($_SESSION['__validated'])) {
session_regenerate_id(true);
$_SESSION['__validated'] = 1;
}
2013-02-18 03:48:21 +01:00
}
function close()
{
2014-05-29 00:39:05 +02:00
// Flush all sessions variables
$_SESSION = array();
// Destroy the session cookie
if (ini_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}
// Destroy session data
2013-02-18 03:48:21 +01:00
session_destroy();
}
function flash($message)
{
$_SESSION['flash_message'] = $message;
}
function flash_error($message)
{
$_SESSION['flash_error_message'] = $message;
}