So, I've scoured the web for a way to block direct access to an image, kind of like hotlinking, but on my website.
For example: going to http://www.mydomain.com/images/someimage.gif should bring the user to a 403 (access denied) page instead of displaying the image. I wanted to do this using .htaccess and for all to know, this is how I did it.
I can use phpThumb (http://phpthumb.sourceforge.net/) to display thumbnails, but someone can also use this to simply "parse" the image, without modifying it in any way (displayed below)
Here's how the .htaccess looks
# normal hotlink prevention requires first 3 lines (3rd line being for my localserver)
# using phpThumb to display my images allows the images to be displayed on the website
# but when tried to access directly ie. http://www.mydomain.com/images/foo.gif
# the user is redirected to error 403 page
# which means I don't need to have those conditions. Infact, with those conditions in place allows users
# to see the images (but still cannot hotlink)
#RewriteCond %{HTTP_REFERER} !^$
#RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.dev/.*$ [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F,NC]
All images are written in this format on my website:
<img src="lib/php/functions/phpThumb/phpThumb.php?src=/lib/images/foo.gif" alt="foo" />
if anyone has any better way to do this, I would gladly appreciate knowing. This is just something I found out on accident actually.