Link to home
Start Free TrialLog in
Avatar of davideo7
davideo7Flag for United States of America

asked on

PHP htaccess Watermark Hotlinked images

I have a PHP script which places a watermark on images on my site.  How could I make it so that it only watermarks my images if they're placed on another site?

Here's my .htaccess code:
RewriteEngine on
    RewriteRule ^(.*\.(jp?g))$ /videogames/watermark.php?image=$1&watermark=watermark.png [NC]

Open in new window


Thanks.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

How could I make it so that it only watermarks my images if they're placed on another site?
How would you envision that your images would get placed on another site?

What I would suggest (without having thought this through in great detail or even tested the idea) would be to use PHP scripts to render your images.  The scripts could check the $_SERVER["HTTP_HOST"] and $_SERVER["HTTP_REFERER"].  It the values indicate your site, render the image unwatermarked.  Else watermark.

If you put the image files outside of your web root they will not be browsable (no URL) and that may help enhance security.
Avatar of davideo7

ASKER

Ray_Paseur: If they got hotlinked.  How would I go about doing this with htaccess?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial