Benjamin Renard
6fdc5447f1
* Code cleaning and fix some small errors using Phpstan * Configure pre-commit to run Phpstan before each commit * Some little improvments and logging, mail, smarty & URL libs * Add Sentry integration * Add Webstat JS code inclusion * Install Smarty dependency using composer Breaking changes: * Rename Event class as HookEvent to avoid conflict with PECL event * URL with refresh GET parameter now automatically trigger redirection without it after page loading to avoid to keep it in URL
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
if (php_sapi_name() == "cli")
|
|
return true;
|
|
|
|
// Define session max duration
|
|
if (!isset($session_max_duration))
|
|
$session_max_duration = (12*60*60); // Default to 12h
|
|
ini_set('session.gc_maxlifetime', $session_max_duration);
|
|
ini_set('session.cookie_lifetime', $session_max_duration);
|
|
|
|
// Start session
|
|
session_start();
|
|
|
|
// Init session key
|
|
if (!isset($_SESSION['session_key'])) {
|
|
$_SESSION['session_key']=uniqid();
|
|
}
|
|
|
|
// Handle session timeout
|
|
if (isset($session_timeout) && $session_timeout) {
|
|
if (!isset($_SESSION['session_last_access'])) {
|
|
logging('DEBUG', 'Set initial session last access');
|
|
$_SESSION['session_last_access'] = time();
|
|
}
|
|
elseif ($_SESSION['session_last_access'] > (time() - $session_timeout)) {
|
|
logging(
|
|
'DEBUG',
|
|
'Session timeout not expired, update session last access '.
|
|
'(Previous value : '.$_SESSION['session_last_access'].')');
|
|
$_SESSION['session_last_access'] = time();
|
|
}
|
|
else {
|
|
logging('INFO', 'Session destroyed due to inactivity');
|
|
session_destroy();
|
|
}
|
|
}
|
|
|
|
function check_session_key($value=null) {
|
|
if (is_null($value) && isset($_REQUEST['session_key']))
|
|
$value = $_REQUEST['session_key'];
|
|
return ($value && $_SESSION['session_key'] == $value);
|
|
}
|
|
|
|
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|