function get_server_answer($url)
{
$url = trim($url);
$urlp = parse_url($url);
// формирование заголовка
$headers['Referer'] = trim($ref);
$headers['User-Agent'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$headers['Host'] = $urlp['host'];
$headers['Accept'] = "text/html, application/xml;q=0.9, application/xhtml+xml;q=0.9, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1";
$headers['Accept-Language'] = "en";
$headers['Accept-Charset'] = "windows-1252, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1";
$headers['Accept-Encoding'] = "deflate, gzip, x-gzip, identity, *;q=0";
$headers['Connection'] = "Keep-Alive";
// соединяем все в кучу
$cmd = "GET " . $urlp['path'] . '?' . $urlp['query'] . " HTTP/1.1" . "\r\n";
if (is_array($headers)) {
foreach($headers as $k => $v) {
$cmd .= "$k: $v" . "\r\n";
}
}
// коннект к хосту
if ($socket == false or feof($socket)) {
if ($debug == 1)echo "коннект к хосту...";
$socket = fsockopen($urlp['host'], 80, &$reply, &$replyString);
@socket_set_timeout($socket, 10);
}
// отправка заголовка
fputs($socket, $cmd . "\r\n");
//получение ответа
$lastLine = "\r\n";
$finished=false;
$headers=array();
while ((!$finished)&&(!feof($socket))){
$str = fgets( $socket, 1024 );
$finished = ( $str == $lastLine );
$headers[]=$str;
}
return $headers;
}