'no-store, private', 'Pragma' => 'no-cache', 'Referrer-Policy' => 'no-referrer', 'X-Content-Type-Options' => 'nosniff', 'Location' => $url, ], ''); exit; } public static function browserRedirectNoStore(string $url): void { self::sendResponse(200, [ 'Content-Type' => 'text/html; charset=UTF-8', 'Cache-Control' => 'no-store, private', 'Pragma' => 'no-cache', 'Referrer-Policy' => 'no-referrer', 'X-Content-Type-Options' => 'nosniff', 'Content-Security-Policy' => "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'", ], self::redirectPageHtml($url)); exit; } public static function redirectPageHtml(string $url): string { $safeUrl = htmlspecialchars($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $jsonUrl = json_encode($url, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); if (!is_string($jsonUrl)) { $jsonUrl = '"/"'; } return '' . '' . '' . 'Zaloguj do serwera poczty' . '' . '

Otwórz panel poczty

' . ''; } public static function errorPage(string $message, int $status): void { $safe = htmlspecialchars($message, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $body = '' . '' . 'Zaloguj do serwera poczty' . '

Zaloguj do serwera poczty

' . $safe . '

' . ''; self::sendResponse($status, [ 'Content-Type' => 'text/html; charset=UTF-8', 'Cache-Control' => 'no-store, private', 'Referrer-Policy' => 'no-referrer', ], $body); exit; } /** * @param array $headers */ public static function rawHttpResponse(int $status, array $headers, string $body): string { $headers['Content-Length'] = (string)strlen($body); $lines = ['HTTP/1.1 ' . $status . ' ' . self::reasonPhrase($status)]; foreach ($headers as $name => $value) { $safeName = preg_replace('/[^A-Za-z0-9-]/', '', (string)$name) ?? ''; if ($safeName === '') { continue; } $safeValue = str_replace(["\r", "\n"], '', (string)$value); $lines[] = $safeName . ': ' . $safeValue; } return implode("\r\n", $lines) . "\r\n\r\n" . $body; } /** * @param array $headers */ private static function sendResponse(int $status, array $headers, string $body): void { if (PHP_SAPI === 'cli') { echo self::rawHttpResponse($status, $headers, $body); return; } http_response_code($status); foreach ($headers as $name => $value) { header($name . ': ' . $value); } header('Content-Length: ' . strlen($body)); echo $body; } private static function reasonPhrase(int $status): string { return match ($status) { 200 => 'OK', 302 => 'Found', 403 => 'Forbidden', 405 => 'Method Not Allowed', 500 => 'Internal Server Error', 502 => 'Bad Gateway', default => 'OK', }; } }