jilo-web/app/includes/session_middleware.php

33 lines
768 B
PHP
Raw Normal View History

2025-02-17 12:36:00 +00:00
<?php
/**
* Session Middleware
2025-02-19 13:31:01 +00:00
*
2025-02-17 12:36:00 +00:00
* Validates session status and handles session timeout.
* If session is invalid, redirects to login page.
2025-02-17 12:36:00 +00:00
*/
function applySessionMiddleware($config, $app_root, $isTest = false) {
// Start session if not already started
if (session_status() !== PHP_SESSION_ACTIVE) {
Session::startSession();
2025-02-19 13:31:01 +00:00
}
// Check session validity
if (!Session::isValidSession()) {
// Session invalid, clean up and redirect
Session::cleanup($config);
// Flash session timeout message
Feedback::flash('LOGIN', 'SESSION_TIMEOUT');
if (!$isTest) {
header('Location: ' . $app_root . '?page=login');
exit();
}
return false;
}
return true;
}