HTTP2::head

HTTP2::head – sends a "HEAD" command

Synopsis

require_once 'HTTP2.php';

array HTTP2::head ( string $url )

Description

Sends a "HEAD" HTTP command to a server and returns the headers in an associative array.

Example

HEAD request to example.com

<?php
require_once "PEAR.php";
require_once 
"HTTP2.php";

$http = new HTTP2();
try {
    
$result $http->head("http://example.com/");
    echo 
"<pre>";
    
print_r($result);
    echo 
"</pre>";
} catch (
HTTP2_Exception $e) {
    echo 
"Error: " $e->getMessage();
}
?>

The output of the print_r() call is shown below.

Parameter

  • string $url - a valid absolute URL

Return value

array - an array containing the header lines or a PEAR_Error.

Example output:

<?php
Array
(
    [
response_code] => 200
    
[response] => HTTP/1.1 200 OK
    
[Date] => Tue25 Nov 2003 22:08:57 GMT
    
[Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [
Last-Modified] => Wed08 Jan 2003 23:11:55 GMT
    
[ETag] => "3f80f-1b6-3e1cb03b"
    
[Accept-Ranges] => bytes
    
[Content-Length] => 438
    
[Connection] => close
    
[Content-Type] => text/html
)
?>

Throws

An exception of type HTTP2_Exception is thrown when an error occurs.

Note

This function can not be called statically.

format a date (Previous) Negotiate language with the user's browser (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.