Для проверки заголовков в PHP можно использовать различные методы. Вот несколько часто используемых подходов:
-
Использование функции
get_headers():$url = 'http://example.com'; $headers = get_headers($url); // Displaying the headers foreach ($headers as $header) { echo $header . "<br>"; } -
Использование расширения
curl:$url = 'http://example.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $headers = curl_getinfo($ch, CURLINFO_HEADER_OUT); // Displaying the headers echo $headers; curl_close($ch); -
Использование функции
stream_context_create():$url = 'http://example.com'; $options = [ 'http' => [ 'method' => 'HEAD' ] ]; $context = stream_context_create($options); $headers = get_headers($url, 0, $context); // Displaying the headers foreach ($headers as $header) { echo $header . "<br>"; }
Эти методы позволяют получать и отображать заголовки заданного URL-адреса в PHP.