Image Grabbing with False Referer

Posted by Mr Carl on Stack Overflow See other posts from Stack Overflow or by Mr Carl
Published on 2010-06-10T16:45:04Z Indexed on 2010/06/10 16:52 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

Hey guys, I'm struggling with grabbing an image at the moment... sounds silly, but check out this link :P

http://manga.justcarl.co.uk/A/Oishii_Kankei/31/1

If you get the image URL, the image loads. Go back, it looks like it's working fine, but that's just the browser loading up the cached image.

The application was working fine before, I'm thinking they implemented some kind of Referer check on their images. So I found some code and came up with the following...

$ref = 'http://www.thesite.com/'; 
$file = 'theimage.jpg';
$hdrs = array( 'http' => array(
 'method' => "GET",
 'header'=> "accept-language: en\r\n" . 
  "Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5\r\n" .
  "Referer: $ref\r\n" . // Setting the http-referer
  "Content-Type: image/jpeg\r\n" 
 )
);
// get the requested page from the server
// with our header as a request-header
$context = stream_context_create($hdrs);

$fp = fopen($imgChapterPath.$file, 'rb', false, $context);
fpassthru($fp);
fclose($fp);

Essentially it's making up a false referrer. All I'm getting back though is a bunch of gibberish (thanks to fpassthru) so I think it's getting the image, but I'm afraid to say I have no idea how to output/display the collected image.

Cheers, Carl

© Stack Overflow or respective owner

Related posts about php

Related posts about image