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, 24 May 2013

view this page in

HttpMessage::getHeader

(PECL pecl_http >= 1.1.0)

HttpMessage::getHeaderConsultar cabecera

Descripción

public string HttpMessage::getHeader ( string $header )

Consulta una cabecera del mensaje.

Parámetros

header

nombre de la cabecera

Valores devueltos

En caso de éxito devuelve el valor de la cabecera, o NULL si la ésta no existiera.



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 | stats | sitemap | contact | advertising | mirror sites