1
0
mirror of git://f0xx.org/ac/ac-platform-php synced 2026-07-29 04:37:53 +03:00
Files
ac-platform-php/platform/shared_session.php
2026-07-11 14:48:27 +02:00

41 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* Shared session for all Android Cast web consoles (crashes, build, …).
* Same cookie path + session name => one login across sub-apps.
*/
function platform_is_https_request(): bool
{
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
return true;
}
$fwd = strtolower(trim((string) ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '')));
if ($fwd === 'https') {
return true;
}
$front = strtolower(trim((string) ($_SERVER['HTTP_FRONT_END_HTTPS'] ?? '')));
if ($front === 'on') {
return true;
}
// Public vhosts are TLS-terminated at the FE; upstream PHP only sees HTTP :80.
$host = strtolower(preg_replace('/:\d+$/', '', (string) ($_SERVER['HTTP_HOST'] ?? '')));
return in_array($host, ['apps.f0xx.org', 's.f0xx.org', 'notify.f0xx.org'], true);
}
function platform_start_session(string $sessionName = 'ac_crash_sess', string $cookiePath = '/app/androidcast_project'): void
{
if (session_status() === PHP_SESSION_ACTIVE) {
return;
}
session_name($sessionName);
session_set_cookie_params([
'lifetime' => 86400,
'path' => $cookiePath,
'httponly' => true,
'samesite' => 'Lax',
'secure' => platform_is_https_request(),
]);
session_start();
}