To confirm:
1. You want to stop hotlinking.
2. You want to log any (failed) attempts at hotlinking.
Is that correct?
1. No, I still require that hot-linking is stopped.
2. Yes, log any hotlinks except from a WhiteList, e.g. facebook, yahoo etc...
I'm not sure if you can write a file using .htaccess, so I don't know how you'd be able to store the information. The easy solution seems to be using mod_rewrite to serve a .php file (or something similar) that logs the attempt.
I tried using PHP which wrote to a text file:
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif|png|jpeg|jpg)$ ../../watermark/watermark.php?hd=maiocv [QSA,NC]
The HTAccess code above was placed before the hot-linking code, but then the hot-linking stopped working, I suppose due to the RewriteRule?
If the request is valid, serve the image. (default)
If the request is hotlinking, serve a php page instead. (use htaccess like you are now, but using mod_rewrite rather than serving an error denying the file)
Now, on that PHP file you will log the information about the request. You can use a database, text files, or anything else you'd like.
You can get the referring URL, and that will tell you the domain. Or you can get the IP of the visitor and log that, although that information is relatively useless because they're are probably just an innocent visitor on whatever other site is using your files.
Finally, if you want it to behave identically as it does now, you can send an HTTP header that the file is denied or whatever you'd like.
Any serverside language can be used instead of PHP. ASP, CGI, JSP, etc.
Bookmarks