downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

HttpMessage::getHeaders> <HttpMessage::getBody
[edit] Last updated: Fri, 14 Jun 2013

view this page in

HttpMessage::getHeader

(PECL pecl_http >= 1.1.0)

HttpMessage::getHeaderGet header

说明

public string HttpMessage::getHeader ( string $header )

Get message header.

参数

header

header name

返回值

Returns the header value on success or NULL if the header does not exist.



add a note add a note User Contributed Notes HttpMessage::getHeader - [1 notes]
up
0
thiago dot henrique dot mata at gmail dot com
2 years ago
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

 
show source | credits | sitemap | contact | advertising | mirror sites