View Single Post
Old 02-09-2007, 12:32 PM  
SmokeyTheBear
►SouthOfHeaven
 
SmokeyTheBear's Avatar
 
Join Date: Jun 2004
Location: PlanetEarth MyBoardRank: GerbilMaster My-Penis-Size: extralarge MyWeapon: Computer
Posts: 28,609
ANTI-HOTLINKING tutorial

- FOR VIDEOS -
ok as requested i will post source here.. you are welcome to clean up the code.

I have posted the easiest method here as an example , there are quite a few additional things you can add to provide more security..

ok here goes

for this example were assuming you have a folder called protected on your server EXAMPLE yourserver.com/protected/

so lets start off with making a folder called "protected" on your server.

Inside that folder should be 2 folders , one we will call "videos" and another we will call "secret"

paths should look like this
yourserver.com/protected/videos
and
yourserver.com/protected/secret

ok save the following as ".htaccess" and upload to the folder called "videos"

Code:
rewriteengine on
 rewriterule ^(.*)\.wmv$ http://www.yoursite.com/protected/?in=$1 [nc]
rewriterule ^(.*)\.jpg$ http://www.yoursite.com/protected/img.php?in=$1 [nc]
nothing else should be in the folder videos. " you could upload a blank index if you want "

ok now copy the following code and save as index.php in the folder "protected"


Code:
<?php
$in = $_GET['in'];
$sip = getenv("REMOTE_ADDR");
$fol = "log.dat";
$sc = file_get_contents($fol);
if (preg_match ("/$sip/", $sc)) {
header("Location: http://yourserver.com/protected/secret/$in.wmv");
}  else
{
header("Location: http://yourserver.com/protected/x.wmv");
}
?>
ok now copy the following code and save as img.php in the folder "protected"

Code:
<?php
$sip = getenv("REMOTE_ADDR");
$in = $_GET['in'];

$fol = "log.dat";
$sc = file_get_contents($fol);
$wrt = "$sip\n$sc";
$wrt = substr($wrt, 0, 10000);
if (preg_match ("/$sip/", $sc)) {
// access granted already
} else {


$hn = fopen($fol, 'w+');
fwrite($hn, $wrt);
fclose($hn);
}

$ft = "http://www.united.com/ual/asset/green_check_12x12.gif";
header("Location: $ft");

?>
finally , place a txt file called log.dat in the "protected" folder and chmod it to be writeable.

ok now all your video links should now point to yourserver.com/protected/videos/example.wmv

in order for the videos to work the surfer will have to have seen the following image
yourserver.com/protected/videos/access.jpg

so if your doing fhg's you should put that image on every page somehwere , doesnt matter the size so if you just wanna make it a hidden image you could zero the width/height.

Or you could tie the forward in the img.php to a banner

you should put a file called x.wmv in the "protected" directory to represent the default BAD VIDEO or you can simply modify the link to a website " ps i recommend using a flash file here because if the user is trying to hotlink your video in a website it would just show a dead video , wheras if you use a flash file as the link it would play your flash video when they try and hotlink it

In the img.php you should point to a small picture or you can tie this into a banner.

what the img.php is for is a security check to make sure the user has viewed the picture first. , when the image is viewed it logs your ip to the log.dat file , when a user attempts to view the video it checks the log.dat to make sure your ip is found. if not it sends to the x.wmv , if it is found it sends you to the proper videos

The REAL videos should go in the "secret" folder as pointed in index.php.

The real video url could be detected so its essential you rename this every now and then in the index.php and the actual folder.. you wont have to change your existing links on your pages at all , just the folder and the pointer in the index.php

p.s. as i mentioned , there are quite a few things you can do to make this more dynamic, i'm more than happy to help anyone with specific customization.

for ease of use i have posted the easiest method for fastest load

If you have any q's ask

If you make a cool mod to this please share / post
__________________
hatisblack at yahoo.com

Last edited by SmokeyTheBear; 02-09-2007 at 12:34 PM..
SmokeyTheBear is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote