Hotlink protection & AListApart


#1

So, I saw AListApart.com’s new artcile about dynamic hotlink protection and I’d love the idea, but when I try to implement it on my site, it doesn’t work. The php page that should be used to display a directly linked image works, but I suspect that dreamhost is doing something funny with mod_rewrite that prevents the .htaccess portion of this to not work properly. Does php need to run as an apahe module in order for this to work properly?


#2

Haven’t tried it myself yet, going to see if it works now, but are htere no errors reported in your Apache logs? (error.log)

:cool: Perl / MySQL / HTML+CSS


#3

I was able to get it to work with PHP-CGI after modifying the PHP code.

header("Cache-Control: no-store, no-cache, must-revalidate");
Should be

Where the change I made was to remove the line break and the extra whitespace.

The error.log was reporting this problem as:


#4

Hey, thanks. They changed the code since they first posted that article. I put the new code in and changed the line to get rid of the line break and whitespace, but it still doesn’t work.The php file will show the file if I browse to it with the query string in the url, but if I browse directly to an image, it doesn’t use the script. There aren’t and suspicious errors in my error log, either :confused: Did you put the exact same code in your .htaccess file, too?


#5

I almost used the same code, you have to change it to match your domain of course.

Let’s say your domain is example.com, then in your .htaccess file you would want this:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC] RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} ![b]example\.com[/b] [NC] RewriteRule (.*) /showpic.php?pic=$1Periods have special meaning so you have to put a \ in front of them. You can leave out the other HTTP_REFERER lines until you make sure its working if you want. I can only think that either your browser has already cached the image, or perhaps you have a path problem.

Try replacing the RewriteRule line with this one:

RewriteRule (.*) http://[b]example.com[/b]/showpic.php?pic=$1 [R]This will do a redirect instead of a rewrite. What this means is that the browser will be told to retrieve the URL http://example.com/showpic.php?pic=whatever.jpg itself instead of being sent just the HTML and the URL in the browser location bar will change.

:cool: Perl / MySQL / HTML CSS


#6

Argh! I give up. The code is exactly correct, with my own domain in place, and still nothing. I don’t get it. I’m going to try switching to an apache module to see if that does it.