'/', 'httponly' => true, 'samesite' => 'Lax']); session_start(); } function csrf_token(): string { if (empty($_SESSION['csrf']) || !is_string($_SESSION['csrf'])) { $_SESSION['csrf'] = bin2hex(random_bytes(32)); } return $_SESSION['csrf']; } function csrf_pruefen(mixed $token): bool { return is_string($token) && isset($_SESSION['csrf']) && is_string($_SESSION['csrf']) && hash_equals($_SESSION['csrf'], $token); } function csrf_verbrauchen(): void { unset($_SESSION['csrf']); } // … die zweite Hälfte (37 weitere Zeilen) gehört zum ganzen Produkt.