Hotlinking?
Moderator: General Moderators
Hotlinking?
How do I check if an image is being hotlinked from my site... Basically I am making a script which watermarks my images if they aren't being read on my webpage.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
look at
and then create a function that will compare some of your values, such as SERVER_ADDR and make sure it is the same as your servers. This will require you keep all your images in a directory perhaps outside your web path, and require a script to call your images for it to be displayed.
Code: Select all
echo '<pre>'. print_r($_SERVER) .'</pre>';But if that is within a script, for example, people who hotlink would use something like this-
<img src="http://www.acdrifter.com/Watermark.php?pic=LKA2154asds" alt="Movie Title" />
Then wouldn't the server values still be my server... not the one calling for the image?
<img src="http://www.acdrifter.com/Watermark.php?pic=LKA2154asds" alt="Movie Title" />
Then wouldn't the server values still be my server... not the one calling for the image?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Mark a .htaccess file that detects if the referer is your website:
Then make watermark.php open the requested image and watermark it.
Obviously you'll need to expand that code to deal with other image types, and you may want to tweak it to calculate the bottom right corner or the middle or something to place the watermark. But thats roughly the sort of thing you'll need.
None of this is tested by the way. So the code is more of a pointer in the right direction that a cut'n'paste solution.
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com.*$ їNC]
RewriteRule (.*)їJj]їPp]їGg]$|(.*)їGg]їIi]їFf]$|(.*)їPp]їNn]їGg]$ watermark.php?image=$1Code: Select all
<?php
$image = imagecreatefromjpg($_GET['image']);
$wm = imagecreatefrompng("watermark.png");
imagecopy($image,$wm,0,0,0,0,50,50);
header("Content-type: image/jpeg");
imagejpeg($image);
?>None of this is tested by the way. So the code is more of a pointer in the right direction that a cut'n'paste solution.
Code: Select all
RewriteEngine on
RewriteLog "e;*********/************/**************/Logs/Hotlinking.log"e;
RewriteLogLevel 1
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.acdrifter.com.*$ їNC]
RewriteRule (.*)їJj]їPp]їGg]$ Watermark.php?pic=$1What's wrong?!
My guess -
There is nothing in the condition about the file being a jpg, and I don't really understand the importance of 'RewriteCond %{HTTP_REFERER} !^$'
Maybe???
Code: Select all
RewriteCond %{HTTP_REFERER} !^http://www.acdrifter.com/ їNC]
RewriteCond %{HTTP_REFERER} .jpg$ їNC]After much mucking around -
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.acdrifter.com/ [NC]
RewriteRule (.*)jpg$ Watermark.php?pic=$1jpg
This works. Yay.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.acdrifter.com/ [NC]
RewriteRule (.*)jpg$ Watermark.php?pic=$1jpg
This works. Yay.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
It's a beautiful thing - I was just checking it out today. The abilities are unbelievable. For example instead of...
http://www.acdrifter.com/?page=Review&m ... 0of%20Fury
You can do
http://www.acdrifter.com/Review/House of Fury/
then rewrite it back to the original...
idk why, but I find that intriguing
http://www.acdrifter.com/?page=Review&m ... 0of%20Fury
You can do
http://www.acdrifter.com/Review/House of Fury/
then rewrite it back to the original...
idk why, but I find that intriguing
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: