From bdc88979651d148b343e2036a4f2c9cd1cb07c7f Mon Sep 17 00:00:00 2001 From: gru Date: Fri, 26 Sep 2025 17:04:57 +0200 Subject: [PATCH] Add test_www.php --- test_www.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test_www.php diff --git a/test_www.php b/test_www.php new file mode 100644 index 0000000..ad88d34 --- /dev/null +++ b/test_www.php @@ -0,0 +1,76 @@ + 0 && $t <= 30) { // ograniczenie timeout do 30s + $timeout = $t; + } + } + + $opts = [ + "http" => [ + "method" => "GET", + "timeout" => $timeout, + "header" => "User-Agent: PHP script\r\n" + ] + ]; + $context = stream_context_create($opts); + + error_clear_last(); + $content = @file_get_contents($url, false, $context); + + if ($content !== false) { + foreach ($http_response_header as $hdr) { + if (preg_match('|^HTTP/\d\.\d\s+(\d+)|', $hdr, $matches)) { + $responseCode = intval($matches[1]); + break; + } + } + + if ($responseCode === 200) { + $responseHeaders = implode("
", $http_response_header); + } else { + $responseHeaders = "Otrzymano kod odpowiedzi HTTP: $responseCode"; + } + } else { + $error = error_get_last(); + $responseHeaders = "Błąd podczas pobierania strony: " . ($error ? htmlspecialchars($error['message']) : 'Nieznany błąd'); + } +} +?> + + + + + + Prosty request HTTP w PHP + + +

Sprawdź stronę HTTP

+
+ + +

+ + +

+ +
+ + +

Odpowiedź serwera:

+
+ + +