<?php
$headers = Array();
$source = "";
$end_head = 0;
$str = "";
$fp = fsockopen("yandex.ru","80");
if ($fp) {
fputs($fp,"GET / HTTP/1.1\r\nHost: yandex.ru\r\nConnection: close;\r\n\r\n");
while (!feof($fp)) {
$str = fgets($fp,1024);
if ($str == "\r\n" || $end_head == 1) {
while (!feof($fp)) {
$source .= fgets($fp,1024);
}
$end_head = 1;
} else {
if (preg_match("%([^ ]+): (.*)\s%",$str,$arr)) {
$headers[$arr['1']] = $arr['2'];
} else {
$headers[] = trim($str);
}
}
}
#print_r($headers);
#echo nl2br(htmlspecialchars($source));
while (list($k,$v) = each($headers)) {
if (preg_match("%^[^0-9]%",$k)) {
header($k.": ".$v."\r\n");
}
}
echo $source;
}
?>