Nov 22, 2009

Prevent People From Linking To Your Downloads

free web hosting
Open Discussion > MODERATED AREA > Tutorials

Prevent People From Linking To Your Downloads

s2city
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

}

?>

 

 

 


Comment/Reply (w/o sign-up)

Saint_Michael
Interesting script it's a smart idea to do something like that. When I check around I saw some other one's smaller in script size and yet do the same thing.

Although this could be effective for those who have many downloads that need a password. But sites like filefront and megaupload make this script somewhat useless since people are saving their bw by uploading somewhere else.

But either way interesting script.

Comment/Reply (w/o sign-up)

biscuitrat
Oooh, very nice! No one ever seems to mention mass-hotlinking downloads, but thank you for this! In some distant future, when I offer templates or assorted goodies again, I'll check back to this...not that I don't have loads more bandwidth than I need currently, but why not smile.gif

Comment/Reply (w/o sign-up)

delivi
wow thats a great piece of code. i had code for preventing others from hotlinking pictures in my site and this will now make my downloads too unvulnerable.

This will save a lot of bandwidth. Thanx friend

Comment/Reply (w/o sign-up)

FaLgoR
That looks just good, could be useful to me as I like to use these kind of downloading codes. Just a simple question here: what exactly does the parse_url() function does? It sounds obvious if you see the code but I'm still a little confuse biggrin.gif could you give me that little tip? thanks smile.gif

Comment/Reply (w/o sign-up)

sportytalk
I agree with the other replies on this thread. That code there is an interesting one, is quite long, but it's very easy to understand and sounds like it does its job.

I don't have a use for a download protection code as I don't have anything on my site which users can download, however, if I ever did have things which were up for download, there's a high chance I'd include a code similar to this one.
(I wouldn't want users from other people's websites coming to my website via a hyperlink to download something. They'd coming onto the website when they aren't actually browsing it or using it like a normal website, they'd be coming only to download, hence they would be using my bandwidth. Additionally, most of the users wouldn't realise they'd been referred to a different site that this other webmaster doesn't own and the users would still think they're on this other website).

As for the parse url, i've just researched it for you on the php manual section of the official php website.

QUOTE
Quote from http://uk2.php.net/manual/en/function.parse-url.php

This function parses a URL and returns an associative array containing any of the various components of the URL that are present.

This function is not meant to validate the given URL, it only breaks it up into the above listed parts. Partial URLs are also accepted, parse_url() tries its best to parse them correctly.


Basically, i haven't ever used the parse_url function but from what I understand it separates the address into each various sections, such as host and port.

Here is another quotation from the php manual. This is the section of the manual which states the various section which can be retrieved by using this parse_url function which s2city used in his code.

QUOTE

Return Values
On seriously malformed URLs, parse_url() may return FALSE and emit a E_WARNING. Otherwise an associative array is returned, whose components may be (at least one):


scheme - e.g. http
host
port
user
pass
path
query - after the question mark ?
fragment - after the hashmark #

If the component parameter is specified a string is returned instead of an array.


Hopefully you will find this post easy to understand.

Thanks for sharing your download protection with us s2city. Even though I most likely won't have a need to use the code, there's bound to be a lot of users that do need to use it and I feel quite confident in saying quite a few users will use your code, even if they don't give you feedback on their views smile.gif

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Prevent Linking Downloads

  1. Check Referrer To Prevent Linking Yours From Other Sites - Check referrer with Php and Mysql (9)
    Check Referrer Using Php To Prevent People Linking To Your Downloads From Other Sites Ever
    find that found some people are listing items, images and tuts and linking directly to the download
    url (those that are like my photoshop tutorial.php?id=0), which is a .php to count the number of
    downloads. 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 my domain, it downloads the file normally, if
    it's not, it will redirect to my home page instead. Important : Not all browser...
  2. Sql Injection, How To Do It, And How To Prevent It - NOT a hacking tutorial, learn how to secure PHP scripts (0)
  3. Php Linking - One of the major advantages of PHP is the ability to create something (4)
    PHP Links Requirements 1. You should understand the majority of PHP (ex: variables, echo, etc.
    www.w3schools.com is a good reference). 2. Experienced with HTML. 3. You need a PHP compatible
    server if you wish to see your results. Description One of the major advantages of PHP is the
    ability to create something similar to an Iframe, only without the scroll-bar. The main advantage of
    this is that you only need one layout page, while the others can be simple 'white space &
    content' pages. Another advantage of this is your web site doesn't look like a fi...
  4. How To Stop Image Hot Linking - for a selected directory. (17)
    Those of you that don't know what is meant by 'hotlinking', it is when someone directly
    links to an image on your site so it will display on their site. This is what is called
    'bandwidth theft' and being as accounts here have a limit on bandwidth, your bandwidth limit
    could be exceeded by someone else hotlinking to your images. As most users of cPanel will know,
    there is an option to disable hotlinking of images in the "Site Management Tools" section.
    However, this disables hotlinking to all directories, what if you only want to disable hotlinki...
  5. [php] Prevent Copying A Template For Each New Page - (0)
    This code means every time you make a page you don't need to copy and paste the HTML code for
    your template, this can make editing links, especially those that appear on every page, and pages a
    lot easier. 1. Make sure that your template is coded so it is fully expandable. 2. Insert this
    code into the content area of your template, and save the file as index.php, instead of .html
    QUOTE $val = $_GET ; // Replace id with whatever you want to use, eg ?id=page $val .= ".html"; //
    Makes the filename complete so if you called ?id=index, it would be index.php it has...
  6. Excluding Your Site From Showing Up On Search Engines - Or how to prevent stalkers from finding your personal site. (0)
    Firstly, I suppose there are very few people here who would want to do this. Most people want
    their sites to be listed on search engines, and these are probably the ones thinking that I must
    have a loose screw or something. But if you use your site for personal blogging and want to keep it
    open to friends and yet prevent your privacy from being infringed upon, this is worth looking at.
    What you need: 1. A text editor. Notepad works fine for me. 2. Coffee. (Not because you're going
    to stay up all night, but because I like to drink coffee for any and every reason po...



Looking for prevent, people, linking, downloads

Searching Video's for prevent, people, linking, downloads
See Also,
advertisement


Prevent People From Linking To Your Downloads

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com