adsad
This commit is contained in:
@@ -3,40 +3,38 @@
|
|||||||
// 0) Umgebung / Domains / Error-Level
|
// 0) Umgebung / Domains / Error-Level
|
||||||
require_once __DIR__ . "/config.php";
|
require_once __DIR__ . "/config.php";
|
||||||
|
|
||||||
// -----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// Session starten (Frontend + API sollen dieselbe Session nutzen)
|
// Session starten (gemeinsam für Frontend + API Subdomains)
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
if (php_sapi_name() !== 'cli') {
|
if (php_sapi_name() !== 'cli') {
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
|
||||||
|
// Einheitlicher Name für alle Teilbereiche
|
||||||
session_name('usbcheck_session');
|
session_name('usbcheck_session');
|
||||||
|
|
||||||
// Cookie-Domain dynamisch bestimmen
|
$isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
||||||
|
|
||||||
|
// Cookie-Domain so wählen, dass ALLE Subdomains von usbcheck.it
|
||||||
|
// dieselbe Session sehen (staging., api.staging., www., …)
|
||||||
$cookieDomain = '';
|
$cookieDomain = '';
|
||||||
if (!empty($_SERVER['HTTP_HOST'])) {
|
if (!empty($_SERVER['HTTP_HOST'])) {
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
// evtl. Port abschneiden
|
|
||||||
$host = preg_replace('/:\d+$/', '', $host);
|
|
||||||
|
|
||||||
// Für alle Subdomains von usbcheck.it dieselbe Session
|
// alles was auf "usbcheck.it" endet, bekommt die gemeinsame Domain
|
||||||
if (preg_match('/\.?usbcheck\.it$/i', $host)) {
|
if (substr($host, -strlen('usbcheck.it')) === 'usbcheck.it') {
|
||||||
// wirkt für usbcheck.it, staging.usbcheck.it, api.staging.usbcheck.it, ...
|
// wirkt für usbcheck.it, staging.usbcheck.it, api.staging.usbcheck.it, ...
|
||||||
$cookieDomain = '.usbcheck.it';
|
$cookieDomain = '.usbcheck.it';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Falls du später andere Projekte auch per Subdomain teilen willst,
|
|
||||||
// kannst du hier weitere Regeln ergänzen, z.B.:
|
|
||||||
// elseif (preg_match('/\.?kusche\.berlin$/i', $host)) {
|
|
||||||
// $cookieDomain = '.kusche.berlin';
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session_set_cookie_params([
|
session_set_cookie_params([
|
||||||
'lifetime' => 0,
|
'lifetime' => 0,
|
||||||
'path' => '/',
|
'path' => '/',
|
||||||
'domain' => $cookieDomain, // WICHTIG: jetzt ggf. .usbcheck.it
|
// WICHTIG: hier die Domain, damit API + Frontend teilen
|
||||||
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
|
'domain' => $cookieDomain ?: '',
|
||||||
|
'secure' => $isHttps,
|
||||||
'httponly' => true,
|
'httponly' => true,
|
||||||
|
// eTLD+1 ist gleich (usbcheck.it), daher reicht Lax für Same-Site
|
||||||
'samesite' => 'Lax',
|
'samesite' => 'Lax',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user