日期:2010-10-06 10:16:00 来源:本站整理
Asp网站操纵躲藏文件途径实现防盗链[网站编程]
本文“Asp网站操纵躲藏文件途径实现防盗链[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
假如我们知道一个静态文件的实际途径如:http://www.xx.com/download/51windows.pdf,假如服务器没有作分外的限制设置,我们便可以毫不吃力的把它下载下来!当网站供应51windows.pdf下载时,怎么样才能让下载者无法得到他的实际途径呢!本文就来介绍若何利用Asp来躲藏文件的实际下载途径.
我们在管理网站文件时,可以把扩大名一样的文件放在同一个目录下,起一个对比分外名字,比方放pdf文件目录为the_pdf_file_s,把下面代码另存为down.asp,他的网上途径为http://www.xx.com/down.asp,我们便可以用http://www.xx.com/down.asp?FileName=51windows.pdf来下载这个文件了,并且下载者无法看到这个文件实际下载途径的!在down.asp中我们还可以设置下载文件能否需求登陆,判断下载的根源页能否为外部网站,从而可以做到避免文件被盗链.
示例代码:
- <%
- From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))
- Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))
- if mid(From_url,8,len(Serv_url)) <> Serv_url then
- response.write "不法链接!" '避免盗链
- response.end
- end if
- if Request.Cookies("Logined")="" then
- response.redirect "/login.asp" '需求登陆!
- end if
- Function GetFileName(longname)'/folder1/folder2/file.asp=>file.asp
- while instr(longname,"/")
- longname = right(longname,len(longname)-1)
- wend
- GetFileName = longname
- End Function
- Dim Stream
- Dim Contents
- Dim FileName
- Dim TrueFileName
- Dim FileExt
- Const adTypeBinary = 1
- FileName = Request.QueryString("FileName")
- if FileName = "" Then
- Response.Write "无效/webpage/asp/041101/24.htm!"
- Response.End
- End if
- FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
- Select Case UCase(FileExt)
- Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
- Response.Write "不法操作!"
- Response.End
- End Select
- Response.Clear
- if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
- Response.ContentType = "image/*" '对图象文件不呈现下载对话框
- else
- Response.ContentType = "application/ms-download"
- end if
- Response.AddHeader "content-disposition", "attachment; 200497141230.htm=" & GetFileName(Request.QueryString("FileName"))
- Set Stream = server.CreateObject("ADODB.Stream")
- Stream.Type = adTypeBinary
- Stream.Open
- if lcase(right(FileName,3))="pdf" then '设置pdf范例文件目录
- TrueFileName = "/the_pdf_file_s/"&FileName
- end if
- if lcase(right(FileName,3))="doc" then '设置DOC范例文件目录
- TrueFileName = "/my_D_O_C_file/"&FileName
- end if
- if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
- TrueFileName = "/all_images_/"&FileName '设置图象文件目录
- end if
- Stream.LoadFromFile Server.MapPath(TrueFileName)
- While Not Stream.EOS
- Response.BinaryWrite Stream.Read(1024 * 64)
- Wend
- Stream.Close
- Set Stream = Nothing
- Response.Flush
- Response.End
- %>
以上是“Asp网站操纵躲藏文件途径实现防盗链[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论