1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cloaking Images Using Php Script

Discussion in 'Black Hat SEO' started by moonlighsunligh, Jul 2, 2012.

  1. moonlighsunligh

    moonlighsunligh Jr. VIP Jr. VIP Premium Member

    Joined:
    May 1, 2010
    Messages:
    1,901
    Likes Received:
    270
    Home Page:
    I want to fetch images from other site and display on my site. I want to store that images in my side temporary only at time of showing on page , so that user think images are coming from my site.is it possible? How? Thanks in advance.

    So when server request picture from location mysite.com/keyword.jpg then the php script should simply get data from merchantsite.com/keyword.jpg and display it as result of the request. It is crucial that google think these images are hosted on my server. Also i do not want to cache those images on my server, it would be the best.

    Here is an solution. but it stores images on my server. I would prefer to read the data directly from the source all the time.

    http://stackoverflow.com/questions/...mage-in-php-only-while-displaying-on-web-page
     
    Last edited: Jul 2, 2012
  2. mrblackjack

    mrblackjack Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 6, 2011
    Messages:
    964
    Likes Received:
    557
    Occupation:
    I live alone, I work alone, I make money alone
    Location:
    G00gle LaNd
    it's pretty simple, use the following code:
    PHP:
    <?php

    // open the file in a binary mode
    $name '/image.png';
    $fp readfile($name'rb');

    // send the right headers
    header("Content-Type: image/png");
    header("Content-Length: " filesize($name));

    // dump the picture and stop the script
    echo fpassthru($fp);
    exit;

    ?>
    this code grabs the image from a remote website, and present it in your website as if it was yours without storing it in your server nor caching it.
     
    • Thanks Thanks x 1
  3. moonlighsunligh

    moonlighsunligh Jr. VIP Jr. VIP Premium Member

    Joined:
    May 1, 2010
    Messages:
    1,901
    Likes Received:
    270
    Home Page:
    Rep added.

    If type of images was jpg u suppose i should use Content-Type: image/jpg ?
     
  4. mrblackjack

    mrblackjack Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 6, 2011
    Messages:
    964
    Likes Received:
    557
    Occupation:
    I live alone, I work alone, I make money alone
    Location:
    G00gle LaNd
    of course. it depends on image type

    moreover, if you would like letting users download the image 'as if from your server' and also rename the image to whatever you like, add the following header to the code:
    header('Content-Disposition: attachment; filename=yourfilename.png');

    right under the Headers list.
     
    • Thanks Thanks x 1
  5. a32337

    a32337 BANNED BANNED

    Joined:
    Jul 2, 2012
    Messages:
    135
    Likes Received:
    44
    this looks pretty sweet
     
  6. moonlighsunligh

    moonlighsunligh Jr. VIP Jr. VIP Premium Member

    Joined:
    May 1, 2010
    Messages:
    1,901
    Likes Received:
    270
    Home Page:
    Yeah, google should be as confused as possible.
     
  7. moonlighsunligh

    moonlighsunligh Jr. VIP Jr. VIP Premium Member

    Joined:
    May 1, 2010
    Messages:
    1,901
    Likes Received:
    270
    Home Page:
    What happens when user click on "view image", so he goes to the image's url: merchantsite.com/keyword.jpg?

    Does server automatically issues 404 error, as the image doesn't really exist or the headers from above solve everything.
     
    Last edited: Jul 3, 2012
  8. mrblackjack

    mrblackjack Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 6, 2011
    Messages:
    964
    Likes Received:
    557
    Occupation:
    I live alone, I work alone, I make money alone
    Location:
    G00gle LaNd
    headers work everything out. Even if the surfer right-click "View Image Info" it will display the image path as if come from your server
     
    • Thanks Thanks x 1
  9. moonlighsunligh

    moonlighsunligh Jr. VIP Jr. VIP Premium Member

    Joined:
    May 1, 2010
    Messages:
    1,901
    Likes Received:
    270
    Home Page:
    Awesome. Please Let me know if final solution looks ok. It should grab an image from location: http://remotesite.com/image/$file and display it as local image $file.

    Also i suppose only this part "header('Content-Disposition: attachment; filename=yourfilename.png');" is responsible for image location. Is that enough to convince Google the file is stored on my server?


    This should be in a wordpress post:
    Code:
    <body>
     <img src="imagesource.php?file=local_image_name.jpg" />
    </body>
    
    Inside imagesource.php
    Code:
    [COLOR=#000000] [COLOR=#0000BB]<?php
    
    [/COLOR][COLOR=#FF8000]// open the file in a binary mode
    [/COLOR][COLOR=#0000BB]$name [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]'http://remotesite.com/image/$file'[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]$fp [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]readfile[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$name[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'rb'[/COLOR][COLOR=#007700]);
    
    [/COLOR][COLOR=#FF8000]// send the right headers
    [/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Content-Type: image/jpg"[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Content-Length: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]filesize[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$name[/COLOR][COLOR=#007700]));
    header ("Content-Disposition:attachment; filename=$file")[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]
    
    [/COLOR][COLOR=#FF8000]// dump the picture and stop the script
    [/COLOR][COLOR=#007700]echo [/COLOR][COLOR=#0000BB]fpassthru[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700]);
    exit;
    
    [/COLOR][COLOR=#0000BB]?>[/COLOR] [/COLOR] 
    
    
     
    Last edited: Jul 3, 2012