Navigation


How To Prevent People From Linking Directly To Your Downloads.

May 26th, 2007, Php, General, admin, Print This Post Print This Post

Ever find that found some people are listing items, images and tuts and linking directly to the download url (those that are like image.php?id=0). To prevent this, you can add a piece of code to the download pages that checks which page referred them to the download page: if it’s your domain, it downloads the file normally, if it’s not, it will redirect to your home page instead.

Important: Not all browsers log referrers, so this won’t work depending on the browser the visitor uses and this method can be also bypassed, but it will work for for the major part of visitors.

CODE
<?php
$yoursite = “yoursite.com”; //Your site url without http://
$yoursite2 = “www.yoursite.com”; //Type your domain with www. this time

$referer = $_SERVER[’HTTP_REFERER’];

//Check if browser sends referrer url or not
if ($referer == “”) { //If not, set referrer as your domain
$domain = $yoursite;
} else {
$domain = parse_url($referer); //If yes, parse referrer
}

if($domain[’host’] == $yoursite || $domain[’host’] == $yoursite2) {

//Run your dowloading code here normally

} else {

//The referrer is not your site, we redirect to your home page
header(”Location: http://yoursite.com”);
exit(); //Stop running the script

}

?>

Webhosting - 0.99$/Pay monthly 1 GB Space, 5GB BW, Cpanel etc

del.icio.us Digg it Earthlink Furl iFeedReaders ma.gnolia Maple.nu Netvouz Netscape RawSugar reddit Scuttle Shadows Simpy Spurl StumbleUpon Wink Yahoo MyWeb

Leave a reply



Last 25 post


Subcribe

    Add to Google Reader or Homepage

    Subscribe in NewsGator Online

    Add to My AOL

    Add Ask N Answer to Newsburst from CNET News.com

    Subscribe in Bloglines

    Subscribe in FeedLounge

Pages


Category


Archive


Links