Events::on('pre_system', static function () {
/*
* --------------------------------------------------------------------
* Session start
* --------------------------------------------------------------------
* We start the session here and not in the controller, so it is also available in the models/libraries...
* which may be executed before the controller is initiated.
* Under CLI, session halts itself so no need to have it.
* See: https://codeigniter.com/user_guide/libraries/sessions.html
*/
if (! is_cli()) {
// When the session starts, PHP executes implicitely `session_cache_limiter('nocache')`
// See: https://www.php.net/manual/en/function.session-cache-limiter
// We prevent PHP from sending headers by using `session_cache_limiter('')`
session_cache_limiter('');
// Start the session (no need for `Services::session()->start()`)
Services::session(); // or: service('session')
}
}