Привет!
Никак не могу грабит сайт mtrk.uz помогите с кодом.
[code]<?php
header("Content-type:text/html;charset=windows-1251"
ini_set('display_errors',1); ini_set ('register_globals', 0);
session_name('SID'); session_start();
$host = 'mtrk.uz';
$path='/'.(!empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
$fp=fsockopen($host,80,$errno, $errstr,10);
if(!$fp) { echo "$errstr ($errno)<br/>\n"; }else{
$data = "";$post=0; foreach($_POST as $key=>$value){
$post=1; $data.="&$key=$value";} if($data)$data=substr ($data,1);
if($post) $headers = "POST $path HTTP/1.0\r\n";else
$headers = "GET $path HTTP/1.0\r\n"; $headers.= "Host: $host\r\n";
$headers.= "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif,image/x-bitmap, */*;q=0.1\r\n";
$headers.= "Accept-Charset: utf-8;q=0.6 windows-1251;q=0.1*;q=0.1\r\n";
$headers.= "Accept-Encoding: utf-8\r\n";
$headers.= "Accept-Language: ru, en;q=0.9\r\n";
$headers.= "User-Agent: ".$_SERVER ['HTTP_USER_AGENT']."\r\n";
if($post){ $headers.= "Content-type: application/x-www-form-urlencoded\r\n";
$headers.= "Content-Length: ".strlen ($data)."\r\n";
$headers.= "\r\n"; $headers.= $data;}else $headers.="\r\n";
Удалён $headers); while($file != "\r\n" $file = Удалён 128);
$file = ''; while(!feof($fp)) $file.= Удалён 4096); Удалён }
//$h = get_headers('http://'.$host.$path);
//echo $headers.'<br /><br /><br /><br />';
//for($i=0; $i<20; $i++){
//echo $h[$i].'<br />';
//}
echo $file;
echo 'test';
?>[/code]
Резултат:
[code]Moved Permanently
The document has moved here.
Apache Server at mtrk.uz Port 80[/code]
Добавлено 14.07.16 в 11:35:19:
Ответ сайта mtrk.uz с get_headers();
[code]HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 14 Jul 2016 08:35:04 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 284
Connection: close
X-Frame-Options: SAMEORIGIN
Location: http://www.mtrk.uz/
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Thu, 14 Jul 2016 08:35:04 GMT
Content-Type: text/html
Content-Length: 0
Connection: close
X-Frame-Options: SAMEORIGIN
location: http://www.mtrk.uz/uz/
X-Powered-By: PleskLin[/code]
<?php
function getPage($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
$res = getPage('http://www.mtrk.uz/uz/');
print_r($res);
?>
Работал с echo file_get_contents('http://'.$host);
только что проверил свой код - работает