关闭

ASP下载系统防盗链方法

标签: aspstreamdomainurlfunctionjavascript
780人阅读 评论(0) 收藏 举报
分类:


以动感下载系统为例:

   打开文件 SoftDown.Asp 在:
   if request.QueryString(ID)= then
   response.write 不能连接或者没有指定下载软件
   response.end
   end if
   的上面或者是下面加上下列代码

   dim strReferer,domain,splDomain,isHttp
   isHttp=false

   '本站下载系统网址列表,不要带上http://
   domain=sron.net,61.156.14.223,61.156.14.227

   splDomain=split(domain,,)
   strReferer=Request.ServerVariables(HTTP_REFERER)
   for iii = 0 to ubound(splDomain)
   if instr(strReferer,trim(splDomain(iii)))>0 then isHttp=True
   next
   if isnull(strReferer) or isHttp=false then
   Response.Write 下载链接来自其他网站,这是不允许的,
   CloseDatabase
   response.end
   end if

用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 "<b>非法链接!<br><span id=yu>3</span><a href=javascript:countDown></a>秒钟后系统将自动返回首页......</b>"
response.write "<meta http-equiv=refresh content=3;url=index.asp>"
response.write "<SCRIPT>valignbottom()</SCRIPT>"
response.write "<script>function countDown(secs){yu.innerText=secs;if(--secs>0)setTimeout('countDown('+secs+')',1000);}countDown(3);</script>"
response.end
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 "无效文件名!"
    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
Response.AddHeader "content-disposition", "attachment; filename=" & GetFileName(Request.QueryString("FileName"))
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
if lcase(right(FileName,3))="rar" then '设置文件类型
TrueFileName = "/files/"&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
%>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12578次
    • 积分:216
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:0篇
    • 译文:0篇
    • 评论:9条
    文章存档
    最新评论
    友情联接