= 1024 && $i < count($units) - 1) { $value /= 1024; $i++; } return ($value >= 10 || $i === 0 ? round($value) : round($value, 1)) . ' ' . $units[$i]; } /** Start the session with hardened cookie settings (idempotent). */ function session_boot(): void { if (session_status() === PHP_SESSION_ACTIVE) { return; } session_set_cookie_params([ 'lifetime' => 0, 'path' => '/', 'secure' => !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', 'httponly' => true, 'samesite' => 'Lax', ]); session_name('fpsid'); session_start(); } /** Redirect and stop. */ function redirect(string $url): never { header('Location: ' . $url); exit; } /** Send a JSON response and stop (used by admin/api.php). */ function json_response(array $payload, int $status = 200): never { http_response_code($status); header('Content-Type: application/json; charset=utf-8'); echo json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; }