diff --git a/config/fileload.php b/config/fileload.php index 7469e92..4fc3eae 100644 --- a/config/fileload.php +++ b/config/fileload.php @@ -4,27 +4,61 @@ require_once __DIR__ . "/config.php"; // ----------------------------------------------------------- -// Session starten +// Session starten (gemeinsam für Frontend + API) // ----------------------------------------------------------- if (php_sapi_name() !== 'cli') { if (session_status() === PHP_SESSION_NONE) { + // Host ermitteln + $host = $_SERVER['HTTP_HOST'] ?? ''; + + /** + * Ziel: + * STAGING: + * - staging.usbcheck.it + * - api.staging.usbcheck.it + * -> Cookie-Domain: .staging.usbcheck.it + * + * PROD: + * - usbcheck.it + * - www.usbcheck.it + * - api.usbcheck.it + * -> Cookie-Domain: .usbcheck.it + * + * LOKAL/SONSTIG: + * - z.B. localhost, 127.0.0.1 + * -> Keine Domain setzen (Browser nimmt Host) + */ + $cookieDomain = ''; + + if (preg_match('~\.staging\.usbcheck\.it$~', $host)) { + // alles unter *.staging.usbcheck.it + $cookieDomain = '.staging.usbcheck.it'; + } elseif (preg_match('~(^|\.)(usbcheck\.it)$~', $host)) { + // usbcheck.it, www.usbcheck.it, api.usbcheck.it, ... + $cookieDomain = '.usbcheck.it'; + } else { + // z.B. localhost → leer lassen + $cookieDomain = ''; + } + + // Einheitlicher Session-Name für alle usbcheck-Hosts session_name('usbcheck_session'); session_set_cookie_params([ 'lifetime' => 0, 'path' => '/', - 'domain' => '', + 'domain' => $cookieDomain, // wichtig für gemeinsame Session über Subdomains 'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'), 'httponly' => true, - 'samesite' => 'Lax', + 'samesite' => 'Lax', // reicht für gleiche Site (staging/api.*.usbcheck.it) ]); session_start(); } } -require_once __DIR__ . '/i18n.php'; // <— NEU: zentrale Sprachlogik +require_once __DIR__ . '/i18n.php'; // zentrale Sprachlogik // ab hier kannst du überall $GLOBALS['lang'] und $GLOBALS['availableLangs'] nutzen // und für JS: @@ -32,6 +66,7 @@ $usbConfig = [ // ... dein sonstiges Zeug ... 'i18n' => app_i18n_get_frontend_config(), ]; + // ----------------------------------------------------------- // 7) Rest des Systems laden // -----------------------------------------------------------