HttpMessage::getHeader
(PECL pecl_http >= 1.1.0)
HttpMessage::getHeader — Get 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.
[an error occurred while processing the directive]
- Функция HttpMessage::addHeaders() - Add headers
- Функция HttpMessage::__construct() - HttpMessage constructor
- Функция HttpMessage::detach() - Detach HttpMessage
- Функция HttpMessage::factory() - Create HttpMessage from string
- Функция HttpMessage::fromEnv() - Create HttpMessage from environment
- Функция HttpMessage::fromString() - Create HttpMessage from string
- Функция HttpMessage::getBody() - Get message body
- Функция HttpMessage::getHeader() - Get header
- Функция HttpMessage::getHeaders() - Get message headers
- Функция HttpMessage::getHttpVersion() - Get HTTP version
- Функция HttpMessage::getParentMessage() - Get parent message
- Функция HttpMessage::getRequestMethod() - Get request method
- Функция HttpMessage::getRequestUrl() - Get request URL
- Функция HttpMessage::getResponseCode() - Get response code
- Функция HttpMessage::getResponseStatus() - Get response status
- Функция HttpMessage::getType() - Get message type
- Функция HttpMessage::guessContentType() - Guess content type
- Функция HttpMessage::prepend() - Prepend message(s)
- Функция HttpMessage::reverse() - Reverse message chain
- Функция HttpMessage::send() - Send message
- Функция HttpMessage::setBody() - Set message body
- Функция HttpMessage::setHeaders() - Set headers
- Функция HttpMessage::setHttpVersion() - Set HTTP version
- Функция HttpMessage::setRequestMethod() - Set request method
- Функция HttpMessage::setRequestUrl() - Set request URL
- Функция HttpMessage::setResponseCode() - Set response code
- Функция HttpMessage::setResponseStatus() - Set response status
- Функция HttpMessage::setType() - Set message type
- Функция HttpMessage::toMessageTypeObject() - Create HTTP object regarding message type
- Функция HttpMessage::toString() - Get string representation
Коментарии
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