|
|
|
| что не так с этим скриптом?rn
<?function get_content($hostname, $path)rn{rn
$line="";rn //станавливаем соединение с узлом $hostnamern
$f=fsockopen($hostname,80, $errno, $errstr, 30);rn
if (!$f) echo "$errstr ($errno)<br />\n";rn //формируем HTTP-запросrn
elsern {rn
$headers = "Get $path HTTP/1.1\r\n";rn
$headers .= "Host: $hostname\r\n";rn
$headers .= "Connection: Close\r\n\r\n";rn
//Отправляем HTTP-запросrn
fwrite($f,$headers);rn
while (!feof($f)){rn
$line .= fgets($f,1024); rn }rn
fclose($f);rn }rn
return $line;rn} rn
$hostname=www_mail_ru;//rn$path= "/";rnrnrn
set_time_limit(180); rn
echo get_content($hostname, $path);?>
|
rnrnна любом хосте: HTTP/1.1 400 Bad request | |
|
|
|
|
|
|
|
для: pBasht
(08.04.2016 в 11:30)
| | может все таки curl?
<?php
function get_content($hostname,$path){
$ch= curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
curl_setopt($ch, CURLOPT_URL, $hostname."/".$path);
$html= curl_exec($ch);
curl_close($ch);
return $html;
}
echo $get_content($hostname,$path)
|
| |
|
|
|