LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

ASP下载系统防盗链三种方法

admin
2010年6月27日 17:29 本文热度 6065

第一方法

两个文件,第一个文件(例子中的index.asp)负责产生随机的下载链接,并将密匙写入cookie;第二个文件(例子中的download.asp)根据cookie找到实际下载地址,然后使用response.addheader和server.transfer来重定向地址。为什么不使用response.redirect呢?是因为response.redirect是在客户端的重定向。如果使用response.redirect,那么真实的下载地址还是传给了客户端,这样防盗链的作用就小了很多,用myie等等浏览器或工具都可以轻易的获得真实下载地址。而iis5.0中提供的server.transfer是服务器端的重定向,与客户端无关,这样客户端就无法获得真实的下载地址。

  下面是id为1的下载文件ttt.exe的防盗链示例程序,具体内容如下:

<!---------------index.asp----------------->
<%response.buffer = true%>
<html>
<head>
</head>
<body>
<%
response.write "下载地址:<br><br>"
randomize
x = int(rnd()*1000)
response.write "<a href='download.asp?id=" & 1*x & "'>ttt.exe</a>"
'这里只是简单的运算,呵呵,这已经足够了。
response.cookies("secret") = x
%>
</body>
</html>

<!---------------download.asp----------------->
<%
response.buffer = true
if request.cookies("secret") = "" then response.end
if not isnumeric(request.cookies("secret")) then response.end
'这里对传递过来的值没有多加判断,只是为了节省篇幅
secret = clng(request.cookies("secret"))
id = clng(request.querystring("id"))
if id/secret = 1 then
response.addheader "content-type","application/x-msdownload"
response.addheader "content-disposition","attachment;filename=ttt.exe"
server.transfer "ttt.exe"
else
response.write "error!"
end if
%>

第二方法
打开文件 softdown.asp 在:
if request.querystring("id")="" then
response.write "不能连接或者没有指定下载软件"
response.end
end if
的上面或者是下面加上下列代码

dim strreferer,domain,spldomain,ishttp
ishttp=false

本站下载cn-media.com/i-v/index.shtm>系统网址列表,不要带上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 "下载链接来自其他网站,这是不允许的,<a href=""./"">请进入本站页面后再进行下载。</a>"
closedatabase
response.end
end if

本站下载cn-media.com/i-v/index.shtm>系统网址列表 就是访问你下载频道网址里的域名,比如你的下载频道可以用多个网址来访问,所以这里用逗号隔开.

当然这里的防盗链只是相对的,只要知道了软件存放地址,防盗链就不管用了.

第三方法

用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>秒钟后cn-media.com/i-v/index.shtm>系统将自动返回首页......</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
%>

该文章在 2010/6/27 17:29:39 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved