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');
}
}
?>