Не могу разобраться с граббером. Помогите.

Discussion in 'PHP' started by inlanger, 29 Jun 2008.

  1. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    Написал граббер, вот код:

    PHP:
    $file=file_get_contents('http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1');
    preg_match_all("#<img src=\"../(.*?)\" />#is",$file,$file1);
    $file=$file1[1][0];
    echo 
    "<img src=http://kit.simplyonline.org/".$file.">";

    Но картинку он не выводит. Если просто перейти перейти по ссылке
    Code:
    http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1
    и нажать на ссылку - Download Picture, то картинка скачается, а вот если взять ссылку на только что сгенерированную картинку, и попытаться открыть её в одтельном окне, то выдаст 403 ошибку...

    Помогите советом :)
     
  2. astrologer

    astrologer Elder - Старейшина

    Joined:
    30 Aug 2007
    Messages:
    837
    Likes Received:
    267
    Reputations:
    59
    Проверяется реферрер.
     
  3. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    И как это обойти?
     
  4. NOmeR1

    NOmeR1 Everybody lies

    Joined:
    2 Jun 2006
    Messages:
    1,068
    Likes Received:
    783
    Reputations:
    213
    Посылаешь сокеты, там указываешь реф.
     
  5. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    PHP:
    <?php
    $fp 
    fsockopen('kit.simplyonline.org'80);
    if(
    $fp)
    {
        
    fputs($fp"POST http://kit.simplyonline.org/output/1214733118.png HTTP/1.0\nReferer: kit.simplyonline.org/barcelona/process.php\n\n");
        echo 
    '<pre>';
        while(!
    feof($fp)) echo fgets($fp);
        echo 
    '</pre>';
        
    fclose($fp);
    }
    ?>
    Не катит... Ответ - HTTP/1.1 403 Forbidden

    http://sportmobile.net/futbolka/test.php
    вот тут лежит мой скрипт...
     
  6. Solker

    Solker Elder - Старейшина

    Joined:
    4 May 2006
    Messages:
    175
    Likes Received:
    53
    Reputations:
    18
    PHP:
    $file file_get_contents('http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1');
    preg_match_all("#<img src=\"../(.*?)\" />#is",$file,$matches);

    $host 'kit.simplyonline.org';

    $sock fsockopen($host80$errno$errstr5); 
    if(!
    $sock){ 
        echo 
    $errstr($errno); 
    }else{
        
    $header "GET /{$matches[1][0]} HTTP/1.1\r\n";
        
    $header .= "Host: $host\r\n";
        
    $header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14\r\n"
        
    $header .= "Keep-Alive: 300\r\n";
        
    $header .= "Connection: keep-alive\r\n";
        
    $header .= "Referer: http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1\r\n\r\n";
            
        
    fwrite($sock$header); 
        while(!
    feof($sock)){ $result .= fgets($sock1024); } 
        
        echo 
    $result;
    }
    Он получает изображение, собственно дальше делай сним что хочеш.
     
    1 person likes this.
  7. .:EnoT:.

    .:EnoT:. Сексуальное чудовище

    Joined:
    29 May 2007
    Messages:
    803
    Likes Received:
    559
    Reputations:
    50
    там просто адрес картинки динамический, никакого рефа там не нужно...
     
  8. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    Как из этого картинку получить?
    http://sportmobile.net/futbolka/test.php
     
  9. .:EnoT:.

    .:EnoT:. Сексуальное чудовище

    Joined:
    29 May 2007
    Messages:
    803
    Likes Received:
    559
    Reputations:
    50
    вот
    PHP:
    <?php
    $file 
    file_get_contents('http://sportmobile.net/futbolka/test.php');
    $img substr($file,strpos($file,"\r\n\r\n")+4);
    header('Content-type: image/png');
    echo 
    $img;
    ?>
     
    1 person likes this.
  10. .::BARS::.

    .::BARS::. Elder - Старейшина

    Joined:
    13 Oct 2007
    Messages:
    379
    Likes Received:
    45
    Reputations:
    10
    сделай вывод картинки вот так...

    PHP:
    <?
    $user_agent "User_agent: Opera/9.50 (Windows NT 5.1; U; ru)\r\n";
    $accept "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";
    $accept_language "Accept-Language: ru, en;q=0.9\r\n";
    $accept_charset "Accept-Charset: utf-8;q=0.6 windows-1251;q=0.1 *;q=0.1\r\n";
    $referer "Referer: http://kit.simplyonline.org/output/\r\n";
    $conection "Connection: Close\r\n";
    $host"kit.simplyonline.org";
    $path="output/".$_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: *\r\n";
    $headers .= "Accept-Charset: UTF-8\r\n";
    $headers .= "Accept-Charset: *\r\n";
    $headers .= "Accept-Encoding: deflate\r\n";
    $headers .= "Accept-Language: ru\r\n";
    $headers .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ru) Opera 9.50\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";
    @
    fwrite($fp$headers);
    while(
    $file != "\r\n"$file = @fgets($fp128);
    $file '';
    while(!
    feof($fp)) $file .= @fgets($fp4096);
    @
    fclose($fp); }
    echo 
    $file;
    ?>
     
    1 person likes this.
  11. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    .::BARS::., пишет, что сервер не может отослать такой хедер
    .:EnoT:.,
     
  12. .:EnoT:.

    .:EnoT:. Сексуальное чудовище

    Joined:
    29 May 2007
    Messages:
    803
    Likes Received:
    559
    Reputations:
    50
    хм, а у меня работает.
    у тебя перед заголовком (header()) скорее всего выводится какой-то текст или ещё что-то, поэтому наверно и не работает. проверь.
    или используй функции кеширования ob_start() и ob_end_flush() например.
     
  13. Solker

    Solker Elder - Старейшина

    Joined:
    4 May 2006
    Messages:
    175
    Likes Received:
    53
    Reputations:
    18
    Вообщем полный ответ, с дополнением от .:EnoT:.
    PHP:
    <?php
    $file 
    file_get_contents('http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1');
    preg_match_all("#<img src=\"../(.*?)\" />#is",$file,$matches);

    $host 'kit.simplyonline.org';

    $sock fsockopen($host80$errno$errstr5); 
    if(!
    $sock){ 
        echo 
    $errstr($errno); 
    }else{
        
    $header "GET /{$matches[1][0]} HTTP/1.1\r\n";
        
    $header .= "Host: $host\r\n";
        
    $header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14\r\n"
        
    $header .= "Connection: Close\r\n";
        
    $header .= "Referer: http://kit.simplyonline.org/barcelona/process.php?name=inlanger&number=5&kit=1\r\n\r\n";
            
        
    fwrite($sock$header); 
        while(!
    feof($sock)){ $result .= fgets($sock1024); } 

        
    $image substr($resultstrpos($result,"\r\n\r\n")+4);
        
        
    header('Content-Type: image/png');
        echo 
    $image;
    }
    ?>
     
    #13 Solker, 30 Jun 2008
    Last edited: 30 Jun 2008
    1 person likes this.
  14. inlanger

    inlanger Elder - Старейшина

    Joined:
    7 Jan 2007
    Messages:
    985
    Likes Received:
    283
    Reputations:
    27
    Solker, спасибо, заработало!