Member
Member
AlexWilson   17-03-2007, 03:54
#1

I've had a nifty anti-leeching/hotlinking solution on my blog for a while, and I've now moved it over to work with my zenphoto installation. I thought I'd share it with those here who might be interested.

This solution has a couple nice features. If the hotlink is a page somewhere else that is just loading your images, it'll just get a broken image. If the hotlink is actually a link directly to the image, a simple page loads -- but since the file to image display page mapping is easy in zp, I've added in some javascript that just forwards to the image page. It also won't break Google Image Search.

The small HTML is much smaller than just about any image file, so you save on bandwidth. You break images for jerks just stealing your images, and you still provide a navigable page for those who follow links to your stuff. Most of the time when people hotlink to your image, the image is in their browser's cache, so they won't realise their html is showing broken images.

You need to do two main things. First is to modify your .htaccess file. My zp installation is in /gallery, so change all references to match your directory:

`

RewriteEngine On

RewriteBase /gallery

hotlinked image protection


RewriteCond %{REQUEST_FILENAME} .(gif|jpe?g|png)$ [NC]

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !alexwilsonphoto.com [NC]

RewriteCond %{HTTP_REFERER} !google. [NC]

RewriteCond %{HTTP_REFERER} !search?q=cache [NC]

RewriteRule (.*) /gallery/showpic.php?pic=/gallery/$1 [R,NC,L]

`

You'll also need to change the alexwilsonphoto.com to match your domain, obviously.

So, that will snag any non-empty referrer that isn't your domain and isn't Google and redirect it to showpic.php.

Next, add this as showpic.php into your zp install dir:

`

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.