note 45420 deleted from function.get-headers by nlopess
| From: | nlopess@php.net | Date: | Thu, 20 Jan 2005 13:20:20 +0000 |
| Subject: | note 45420 deleted from function.get-headers by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83679@lists.php.net to get a copy of this message | ||
Note Submitter: cpurruc fh-landshut de
----
Both backports are bad! For getting header meta data, you should use HEAD instead of GET.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
for details!
<?php
/**
* @return array
* @param string $url
* @desc Fetches all the headers
* @author cpurruc fh-landshut de
*/
function get_headers_php4( $url )
{
$url_info = parse_url( $url );
$fp = fsockopen( $url_info['host'],80,$errno,$errstr,30 );
if ($fp)
{
$head = "HEAD
".$url_info['path']."?".$url_info['query']."
HTTP/1.0\r\n" .
"Host: ".$url_info['host']."\r\n\r\n";
fputs( $fp, $head );
while( !feof($fp ) )
{
$header[] = fgets( $fp, 1024 );
}
return $header;
}
}
?>