How to tell if an image is being hotlinked...

Discussion in 'Programming' started by awesty, Jun 8, 2007.

  1. #1
    Is there anyway to be able to tell if an image you are hosting is being viewed on another site, and if so tell which image it is and run a script when it is viewed?

    thanks :)
     
    awesty, Jun 8, 2007 IP
  2. renoir

    renoir Well-Known Member

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    118
    #2
    well, you can see my blog for an example of image hotlinking.

    you can stop it with .htaccess mod_rewrite
     
    renoir, Jun 8, 2007 IP
  3. awesty

    awesty Active Member

    Messages:
    247
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I had a look but couldnt find the article. can you give me a direct link?

    i am not trying to stop people hotlinking, i just want to run a php script that will update a database everytime an image is viewed on any site.
     
    awesty, Jun 9, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Couple of ways you could do it, are you wanting to track all images or all images from a particular location, gimme a look at an example url of an image you want to track.

    I would rewrite image urls to a php script, lets assume your images are in /hotlinked/

    
    RewriteEngine On
    RewriteRule ^/hotlinked/(.*)$ count_my_images.php?image=$1
    
    Code (markup):
    count_my_images.php =
    
    <?
    if( file_exists( sprintf( '/hotlinked/%s', $_GET['image'] ) ) )
    {
      update_my_data_base( $_GET['image'] );
      echo file_get_contents( sprintf( '/hotlinked/%s', $_GET['image'] ) );
    }
    else
    {
     echo file_get_contents( '/hotlinked/404.image.jpg' );
    }
    
    PHP:
    That code prolly won't actually work for you, is an example, gimme some more details and I'll write something that does.....
     
    krakjoe, Jun 9, 2007 IP
  5. awesty

    awesty Active Member

    Messages:
    247
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    okay, thanks. i will mess around with the code you gave me.
     
    awesty, Jun 9, 2007 IP