Session: add directory_path config parameter

This commit is contained in:
Benjamin Renard 2023-03-07 18:29:34 +01:00
parent fe75984bc7
commit fe19313c2f
5 changed files with 25 additions and 4 deletions

1
example/data/sessions/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
sess_*

View file

@ -102,8 +102,12 @@ i18n:
# Session
#
session:
timeout: 1800 # Session timeout dur to inactivity (in seconds)
max_duration: 43200 # Session max duration (in seconds, default : 12h)
# Session timeout due to inactivity (in seconds)
timeout: 1800
# Session max duration (in seconds, default : 12h)
max_duration: 43200
# Directory path where to store PHP sessions data (optional, default: use system default)
directory_path: "${data_directory}/sessions"
#
# Database configuration

View file

@ -102,8 +102,12 @@ i18n:
# Session
#
session:
timeout: 1800 # Session timeout dur to inactivity (in seconds)
max_duration: 43200 # Session max duration (in seconds, default : 12h)
# Session timeout due to inactivity (in seconds)
timeout: 1800
# Session max duration (in seconds, default : 12h)
max_duration: 43200
# Directory path where to store PHP sessions data (optional, default: use system default)
directory_path: "${data_directory}/sessions"
#
# Database configuration

1
skel/data/sessions/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
sess_*

View file

@ -30,6 +30,7 @@ class Session {
array(
'max_duration' => 43200, // 12h
'timeout' => null,
'directory_path' => null,
)
);
@ -38,6 +39,16 @@ class Session {
Config :: ini_set('session.gc_maxlifetime', strval(self :: $max_duration));
Config :: ini_set('session.cookie_lifetime', strval(self :: $max_duration));
// Set custom session directory (if configured)
$directory_path = App::get('session.directory_path', null, 'string');
if ($directory_path) {
Log :: trace('Set session directory path as "%s"', $directory_path);
if (!session_save_path($directory_path)) {
Log :: warning('Fail to set session directory path as "%s"', $directory_path);
}
}
Log :: debug('Use session directory "%s"', session_save_path());
// Start session
session_start();