Repository navigation
Internals Session SessionHandler
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/session/SessionHandler.php · Snapshot 8411f4287706.
Session handling reads database settings, starts PHP sessions, and maintains session metadata. SessionHandler() is an explicit method, not a PHP constructor.
use setting\Config;class SessionHandlerDeclarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $time | private string $time; |
Used by SessionHandler(). |
| Method | Signature |
|---|---|
| SessionHandler | public function SessionHandler(): bool |
| sessionClearing | protected function sessionClearing(): void |
| sessionDumper | public function sessionDumper(): void |
public function SessionHandler(): boolInitializes and manages session handling.
- Starts the session if it’s not already active.
- Configures session cookie parameters such as SameSite, Secure, and HttpOnly based on configuration.
- Tracks session start time and manages session expiration and ID regeneration.
- Optionally binds session to a client IP address to prevent session hijacking.
- Clears the session when necessary (e.g., expiration, IP mismatch).
@return bool True if the session is successfully handled, false if session clearing occurs due to IP mismatch.
State writes: $this->time.
Return expressions (including local callbacks): true.
External effects include session_start, session_regenerate_id.
Implementation, validation guards and interaction order
/**
* Initializes and manages session handling.
*
* - Starts the session if it’s not already active.
* - Configures session cookie parameters such as SameSite, Secure, and HttpOnly based on configuration.
* - Tracks session start time and manages session expiration and ID regeneration.
* - Optionally binds session to a client IP address to prevent session hijacking.
* - Clears the session when necessary (e.g., expiration, IP mismatch).
*
* @return bool True if the session is successfully handled, false if session clearing occurs due to IP mismatch.
*/
public function SessionHandler(): bool
{
$this->time = time();
if (session_status() !== PHP_SESSION_ACTIVE) {
$sameSite = Config::getConfig("AWT", "Session SameSite")->getValue();
$sameSite = ($sameSite == 'true') ? "Strict" : "None";
$secure = Config::getConfig("AWT", "Session HTTPS Only")->getValue() == 'true';
$httpOnly = Config::getConfig("AWT", "Session HTTP Only")->getValue() == 'true';
session_set_cookie_params([
"SameSite" => $sameSite,
"Secure" => $secure,
"HttpOnly" => $httpOnly
]);
session_start();
}
$_SESSION['sessionInfo']['started'] = $_SESSION['sessionInfo']['started'] ?? $this->time;
if (isset($_SESSION['sessionInfo']['expires'])) {
if ($_SESSION['sessionInfo']['expires'] < $this->time) {
$this->sessionClearing();
} else {
$_SESSION['sessionInfo']['expires'] += Config::getConfig("AWT", "Session ID Regeneration Time")->getValue();
}
}
if (isset($_SESSION['sessionInfo']['regenerate_id'])) {
if ($this->time - $_SESSION['sessionInfo']['regenerate_id'] > 10) {
$_SESSION['sessionInfo']['regenerate_id'] = $this->time;
session_regenerate_id(true);
}
} else {
$_SESSION['sessionInfo']['regenerate_id'] = $this->time;
}
return true;
}protected function sessionClearing(): voidExternal effects include session_destroy.
Implementation, validation guards and interaction order
protected function sessionClearing(): void
{
unset($_SESSION);
unset($_COOKIE['LAST_IP']);
session_destroy();
}public function sessionDumper(): voidComputes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
public function sessionDumper(): void
{
var_dump($_SESSION);
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes