• PHP Video Tutorials

PHP - get_headers() Function



get_headers() function can fetch all headers sent by the server in response to an HTTP request.

Syntax

array get_headers( string $url [, int $format = 0 ] )

get_headers() function can return an array with headers sent by the server in response to an HTTP request.

get_headers() function can return an indexed or associative array with headers, or false on failure.

Example-1

<?php
   $url = "http://www.tutorialspoint.com";

   print_r(get_headers($url));
   print_r(get_headers($url, 1));
?>

Example-2

<?php
   stream_context_set_default(
      array(
         "http" => array(
            "method" => "HEAD"
         )
      )
   );
   $headers = get_headers("http://www.tutorialspoint.com");
?>
php_function_reference.htm
Advertisements