I arrived here looking for a way to collect headers sent by a remote server. No such luck; so:
<?php
function get_headers($host, $url)
{
$headers = array();
$fp = fsockopen ($host, 80, $errno, $errstr, 45);
if ($fp)
{
fputs ($fp, "GET $url HTTP/1.0\r\n\r\n");
while (!feof($fp))
{
$char = fgetc($fp);
if($char === "\n")
{
if (ord($header) === 13) { return($headers); }
else { array_push($headers, trim($header)); }
unset($header);
}
else { $header = $header.$char; }
}
fclose ($fp);
}
}
?>
print_r(get_headers("php.net", "/"));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 02 Sep 2006 13:47:02 GMT
[2] => Server: Apache/1.3.37 (Unix) PHP/5.2.0-dev
[3] => X-Powered-By: PHP/5.2.0-dev
[4] => Last-Modified: Sat, 02 Sep 2006 13:21:09 GMT
[5] => Content-language: en
[6] => Set-Cookie: COUNTRY=USA%2C68.37.136.230; expires=Sat, 09-Sep-2006 13:47:02 GMT; path=/; domain=.php.net
[7] => Connection: close
[8] => Content-Type: text/html; charset=utf-8
)