How can i allow downloads only from my site?

Discussion in 'HTML & Website Design' started by awaisuk, Dec 12, 2007.

Thread Status:
Not open for further replies.
  1. #1
    How can i allow downloads only from my site?

    Hey,

    Say i got 2 domains. one is www.test.com the other is www.site.com

    My main site is www.site.com and my downloads are hosted on www.test.com

    Lets say for example the file is www.test.com/file.rar

    And i want people to download it ONLY when they are on my main site which is www.site.com

    So when they are on the main site, the download will work, and when they are not it will not work.

    How can i do this?

    Thanks.
     
    awaisuk, Dec 12, 2007 IP
  2. zorde

    zorde Peon

    Messages:
    382
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    zorde, Dec 12, 2007 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sounds like they want the opposite of that of only allowing hotlinking

    I am sure you could do it with .htaccess if you are on an apache server alternatively it would be hard to code it in any serverside langauge
     
    AstarothSolutions, Dec 12, 2007 IP
  4. awaisuk

    awaisuk Banned

    Messages:
    1,013
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well i dont want people to download off my links they got from somewhere else, i want the download links to work only when they are on my main site...

    How can i do that?
     
    awaisuk, Dec 13, 2007 IP
  5. glasshoper

    glasshoper Peon

    Messages:
    373
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i wonder if that's possible since the two site's are on two different domain names, if they were two different sub domain i think there is a possibility.
     
    glasshoper, Dec 13, 2007 IP
  6. BTS

    BTS Active Member

    Messages:
    184
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #6
    You can Do it with .htacces
    I'm not sure but Try this :
    create .htaccess at test.com
     
    BTS, Dec 13, 2007 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You would need to do a deny from the all other sources - we dont use Apache servers so dont know .htaccess at all.

    The other simple way of doing it is to have the true file out of the public domain and link to a aspx/ php file which checks the referrer is from the correct domain, if it is then to serve up the file and if it isnt then to display an error message/ redirect etc
     
    AstarothSolutions, Dec 13, 2007 IP
  8. awaisuk

    awaisuk Banned

    Messages:
    1,013
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks for the replies.

    Can you show me how i would do that? Any toturial? Because thats exactly what i need :)

    Thanks again
     
    awaisuk, Dec 13, 2007 IP
  9. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #9
    the code below is a basic example in ASP/ VB.Net to achieve what you want - if you have multiple files you would remove the hard coding of the filename but instead request a querystring element that contains the file name so that the one downloader could be used for all the files.

    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Request.UrlReferrer.Host.Contains("test.com") Then
                Dim path As String = Server.MapPath("thefilename.zip")
                Dim file As System.IO.FileInfo = New System.IO.FileInfo(path)
                If file.Exists Then 'set appropriate headers
                    Response.Clear()
                    Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
                    Response.AddHeader("Content-Length", file.Length.ToString())
                    Response.ContentType = "application/octet-stream"
                    Response.WriteFile(file.FullName)
                    Response.End()
                Else
                    '''' enter action for if the file doesnt exist
                End If
                file = Nothing
            Else
                '''' if from invalid link redirect
                Response.Redirect("http://www.test.com")
            End If
        End Sub
    Code (.Net):
     
    AstarothSolutions, Dec 13, 2007 IP
Thread Status:
Not open for further replies.