首页 | 心情日记 | 建站心得 | 编程技术 | 大盘分析 | 股市信息 | 学习园地 | 电脑技巧 | 物流外贸 | 另类其它 | 站长推荐 | 给我留言 | 相册

用户登陆
用户:
密码:
 
不保存保存一天
保存一月保存一年

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论

日志搜索

 标题   内容


ASP 编程中 20 个非常有用的例子 防盗链ASP代码三则
未知 ASP下载系统防盗链方法   [ 日期:2006-09-25 17:08:08 ]   [ 来自:本站原创 ]

海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继 淘宝店:http://shantan.taobao.com 云邮科技官网:www.yunrelay.com

【字体设置:
ASP下载系统防盗链方法 

第一方法

    两个文件,第一个文件(例子中的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
 


暂时没有评论
   发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:  我要注册 验证码: 
为防止广告注册机程序,验证码不会自动显示,请点击此处显示或者(刷新)验证码!
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字
确定发布?
最多可以输入200个字,目前你已经输入了0个字;你今日还可以发表10条评论!
 
   

CopyRight © 2008-2010 广东金融学院030904班 All Rights Reserved
Powered by www.030904.com