Block Image Hotlinking Script and Code

Hotlinking full resolution photos and images has become a big problem on the internet. Even the search engines are doing it,
basically stealing your content and page views. This script and code will protect your site from this outlandish practice.

PNG Image
Create your own png watermark image, around 400px by 400px and name it watermark.png or use the image below.

Image Watermark Script
Copy the code below and make a file called watermark.php
About 15 lines down, you can change the '_thumb' to be your thumbnail images file name to not include these.
Upload the watermark.php and watermark.png files to your public directory.

watermark.php

.htaccess
Put these lines of code in your .htaccess file.
If you don't know how, here's how:
Make a file on your computer called htaccess.txt
Put these lines of code in it and change the 'yoursite.com' to be your site.
Change the 'yoursiteusername' to be your sites user name. This is to ensure the images load normally at your site.
The code below is set up for jpg files, you can change this on the last line by changing jpg to gif in both places for example.
Upload htaccess.txt to your public directory. Delete your existing .htaccess file (but download it first to save any code already there).
Finally, change the name of htaccess.txt to .htaccess on your server.
RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} !googlebot [NC]
RewriteCond %{HTTP_USER_AGENT} !msnbot [NC]
RewriteCond %{HTTP_USER_AGENT} !slurp [NC]
RewriteCond %{HTTP_USER_AGENT} !bingbot [NC]
RewriteCond %{HTTP_REFERER} !^http://yoursite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://yoursite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com$      [NC]
RewriteCond %{DOCUMENT_ROOT} !^yoursiteusername      [NC]
RewriteRule (.+).jpg http://www.yoursite.com/watermark.php?src=$1.jpg [NC]
Donation
This script is free but feel free to make a donation. Thankyou!



Home