(PECL pecl_http >= 1.1.0)
HttpMessage::getHeader — Get header
$header
)Get message header.
header
header name
Returns the header value on success or NULL
if the header does not exist.
thiago dot henrique dot mata at gmail dot com (2011-03-19 12:31:25)
This can be good to ping external web sites, get the content type, length, etc.
<?php
function get_http_header( $strUrl )
{
$arrHeader = array();
$arrHeader[ 'url' ] = $strUrl;
try
{
$arrLines = explode( "\n" , http_head( $strUrl ) );
}
catch( Exception $objException )
{
return
array(
"response" => "timeout" ,
"url" => $strUrl
);
}
$arrHeader['response'] = array_shift( $arrLines );
foreach( $arrLines as $strLine )
{
$arrLine = explode( ":" , $strLine );
if( sizeof( $arrLine ) == 2 )
{
$arrHeader[ $arrLine[0] ] = $arrLine[1];
}
}
return $arrHeader;
}
print_r( get_http_header( "http://www.example.com" ) );
?>
Array
(
[url] => http://www.example.com
[response] => HTTP/1.1 200 OK
[Server] => Microsoft-IIS/5.0
[X-Powered-By] => ASP.NET
[Content-Type] => text/html
[Accept-Ranges] => bytes
[Content-Length] => 465