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

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.
Who is Participating?
R_HarrisonConnect With a Mentor Commented:
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

pixalaxAuthor Commented:
Thank you very much.
pixalaxAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.