Session Management
Relevant source files
The following files were used as context for generating this wiki page:Introduction
Session management in the oldwebsite project is a dual-system approach that handles state persistence on both the server and the client. On the server-side, it utilizes standard PHP sessions primarily to maintain the user's language preference across different pages. On the client-side, it employs the browser's localStorage to manage the visibility of UI components, such as the cookie consent banner, ensuring a consistent user experience across browsing sessions.
The system is designed to be straightforward. PHP scripts at the entry point of each page initialize the session and handle language selection logic. A corresponding JavaScript file manages client-side state, which also includes logic for controlling UI elements like the navigation bar on specific pages like the login screen.
Server-Side Session (PHP)
The core of the server-side state management relies on PHP's native session handling. This is consistently implemented across all main PHP entry-point files.
Sources: login.php, index.php, inside/overview.php, iite/company.php
Initialization
On every page load, a session is started by calling session_start() at the beginning of the script. This makes the $_SESSION superglobal available for storing and retrieving user-specific data.
Sources: login.php:2, index.php:2, inside/overview.php:2
Language Preference Management
The primary use of PHP sessions in this application is to store and recall the user's selected language.
The following diagram illustrates the process for determining the language on each page request.
This diagram shows how the server checks for a language parameter, updates the session, and then falls back to the session or a default value.
Sources: login.php:4-12, index.php:4-12, inside/overview.php:4-12
- The script checks if a
langGET parameter exists in the URL. - If it exists, the value is saved to
$_SESSION['lang']. The server then issues aheader("Location: ...")redirect to the same URL without the query parameter to provide a cleaner address for the user. - If the
langparameter does not exist, the script attempts to retrieve the language from$_SESSION['lang']. - If
$_SESSION['lang']is not set, it defaults to'it'(Italian).
Session Variables
The system uses a single, well-defined session variable.
| Variable | Type | Description | Default Value | Source Files - |
| $_SESSION['lang'] | string | Stores the user's selected language code (e.g., 'en', 'it', 'fr', 'es'). | 'it' | login.php:4-12, index.php:4-12 |
Client-Side State Management
Client-side state is managed using JavaScript and the browser's localStorage API, primarily for UI persistence that doesn't require server interaction.
Sources: apps/js/iite_components.js
Cookie Consent Banner
The application displays a cookie consent banner which uses localStorage to remember the user's choice.
This diagram shows the logic for displaying and hiding the cookie consent banner based on localStorage.
Sources: apps/js/iite_components.js:60-91
- State Tracking: On page load, the script checks for a
localStorageitem with the keycookies. - Hiding Logic: If the value of this item is
'hidden', the banner is immediately hidden (display: 'none'). - User Action: When a user clicks either the accept (
btn-cookies) or decline (btn-cookies-decline) button, the script sets thelocalStorageitemcookiesto'hidden'and adds CSS classes to hide the banner. This prevents it from appearing on subsequent navigations.
Local Storage Keys
| Key | Value | Description | Source File |
|---|---|---|---|
cookies | hidden | Indicates that the user has acknowledged the cookie banner, and it should not be shown again. | apps/js/iite_components.js:69,82,89 |
Session-Dependent UI Rendering
The application alters the UI based on the current page, which is indirectly related to session state as it affects non-authenticated and authenticated sections.
Navbar Visibility
The main navigation bar is conditionally hidden on certain pages, such as the login page. This is implemented with both server-side and client-side logic to ensure a smooth rendering experience.
Server-Side Logic
In login.php, a $hideNavbar flag is set to true if the current page is in a predefined list. This flag is intended to be used by the main layout template (layout.phtml) to prevent the navbar from being rendered in the HTML.
Sources: login.php:22-29
Client-Side Fallback
To prevent a "flash" of the navbar before the server-rendered HTML is fully parsed, apps/js/iite_components.js includes a client-side fallback. It checks the URL path and, if it matches a page in its hideNavPages list, it immediately hides the navbar elements using CSS.
Sources: apps/js/iite_components.js:48-58
Pages with Hidden Navbar
| Page/Route Pattern | Logic Source | Description |
|---|---|---|
login | login.php:24 | The server-side $page variable is 'login'. |
auth | login.php:25 | The server-side $page variable is 'auth'. |
/login, /login.php | apps/js/iite_components.js:50-51 | The client-side window.location.path includes one of these strings. |
body.hide-navbar | themes/css/design.css:1614-1617 | A body class can be used to hide the navbar via CSS display: none !important;. |
Conclusion
The session management system in oldwebsite is a practical and bifurcated solution. It leverages the strengths of both server-side and client-side persistence mechanisms for their most appropriate use cases. PHP sessions are used for critical cross-page data like language preference, while client-side localStorage is used for non-critical UI state like banner visibility. While the provided files do not show a full user authentication flow, the infrastructure in login.php and the associated UI-hiding logic strongly suggest a system for managing authenticated user sessions is intended.