How to create temporary download links with limited to 1 IP address?

Posted on 2008-11-06
Last Modified: 2012-05-05
Hello all,

I want to add download section to my website. There are already 3 kind of user groups.
2 paid, and 1 free.

 For free users I don't have problem but for paid users, I will add files to my server that's why all the links has to be hidden and if user is not logged in, can't download the paid link.

1. Paid user will click download.
2. Script will create the download  links which will be expired in 24 hours  & 3 download attempts.
3. Paid download links (for paid members) should be locked to user's ip address to eliminate link sharing.
4. I would like to also hide the location of the file while user is downloading, if it is possible in the end it is all about it.

I will be glad if someone can help me out with that.
Question by:pixalax
    LVL 12

    Accepted Solution

    If you use the code below you can stream a file to the browser, the file does not need to be on your website only on the server (you may need to set permissions for the IUSER on the folder).  However as the folder does not need to be in your website it can't be accessed directly from a browser.

    I would suggest setting up some sort of database to store and track the information regarding access to the files.  Then add code to verify the user is entitled to access to the top of the page below.

    You may need to bear in mind that IP addresses can change?
    Dim filepath
    filepath = "C:\SomeLocationOnYourServer\somefile.doc"
    filename=right(filepath, len(filepath)-instrrev(filepath, "\"))
    Response.Buffer = true
    TransferFile = True
    Set objStream = Server.CreateObject("ADODB.Stream") 
    objStream.Type = 1		
    objStream.LoadFromFile filepath
    Response.AddHeader "Content-Disposition","attachment;filename=" & filename
    Response.ContentType = MimeType
    Response.AddHeader "Content-Length", objStream.Size
    Response.ContentType = MimeType
    Response.BinaryWrite objStream.Read
    Set objStream = Nothing

    Open in new window

    LVL 2

    Author Closing Comment

    Thank you very much.
    LVL 2

    Author Comment

    Thanks a lot for your explanations.

    Since nobody is going to see or try to have access and also I can protect my files in that way, so there is no problem with that. The basic is the protect the files location.

    Thank you very much, tested and it works.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now