第一種:
終于對下載系統做了個(gè)防盜鏈措施,在下載的頁(yè)面頭部做了如下代碼,相關(guān)代碼如下:
<%
From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))
Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(From_url,8,len(Serv_url)) <> Serv_url and mid(From_url,8,len(Serv_url))<>"ITstudy.cn" and mid(From_url,8,len(Serv_url))<>"www.ITstudy.cn" then
response.write "您下載的軟件來(lái)自IT學(xué)習網(wǎng),請直接從主頁(yè)下載,謝謝<br>" ’防止盜鏈
response.write "<a href=http://www.ITstudy.cn>IT學(xué)習網(wǎng)http://www.ITstudy.cn<;/a>" ’防止盜鏈
response.end
end if
%>
第二種:
<%
’定義函數,用ADODB.Stream讀取二進(jìn)制數據
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.LoadFromFile FileName
ReadBinaryFile = BinaryStream.Read
End Function
Response.AddHeader "Content-Disposition", "attachment;filename=2.gif"’文件名
Response.ContentType = "image/GIF" ’設置(1)
response.Binarywrite ReadBinaryFile(server.mappath("2.gif"))’就是你讀取存在本地的文件,防止被
別人知道真實(shí)路徑盜連的。
%>
(1)下面的示例將 ContentType 屬性設置為其他的常見(jiàn)值。
text/HTML 這個(gè)就不說(shuō)了
image/GIF gif圖片
image/JPEG jpg圖片
application/x-cdf cdf文檔
application/wma 就是西瓜哪個(gè)音樂(lè )類(lèi)型了
具體可以參照 Web 瀏覽器文檔或當前的 HTTP 規格說(shuō)明
這樣再利用asp的儲存session,cookies,以及讀取HTTP頭等特殊功能就可以完全真正的實(shí)現防盜連,這里
沒(méi)有設置緩存,如果訪(fǎng)問(wèn)量巨大,我想設置下就會(huì )更好吧。
第三種:
最簡(jiǎn)單的用Active Server Pages防站外提交表單、跨站提交表單、防盜鏈……
方法:Request.SeverVariables("HTTP_REFERER")
解釋?zhuān)寒斈橙送ㄟ^(guò)鏈接到達當前頁(yè),HTTP_REFERER 就保存了這個(gè)用戶(hù)的來(lái)源(來(lái)路)
舉個(gè)例子,這個(gè)例子很簡(jiǎn)單,只是拋磚引玉而已,大家可以增加更多的功能。
如下,只有首先從“ http://www.ITstudy.cn”登陸才能看到文件內容。
源碼:index.asp
<html>
<head><title>最簡(jiǎn)單的用asp防盜鏈</title></head>
<body>
<%
Option.Explicit
Response.Buffer=Ture
%>
<%
CheckUrl("http://ITstudy.cn/index.jsp";)
%>
<%
Function CheckUrl(url)
Dim Where:Where=Request.SeverVariables("HTTP_REFERER")
If Where=url Then
Call main()
Else
Response.write("很抱歉,您必須從"&url&"訪(fǎng)問(wèn)才能進(jìn)來(lái)!")
End if
End Function
%>
<%
Sub main()
Response.write("這兒是你要顯示的網(wǎng)頁(yè)內容")
End sub
%>
</body>
</html>
該方法對防止盜鏈文章、站外提交表單、跨站提交表單還比較有效,對于軟件盜鏈比如.rar.zip.exe等倒沒(méi)什么作用。
不知各位讀者是否有好的主意,呵呵。
還有一種方法就是用判斷服務(wù)器及上一頁(yè)的地址來(lái)完成。
<%
dim from, local
from = request.ServerVariables("HTTP_REFERER")
local = request.ServerVariables("SERVER_NAME")
If mid(from, 8, local)<>Len(local) Then
response.write "不要從外部提交數據"
else
call main()
end if
sub main()
’你的主體內容
end sub
%>
聯(lián)系客服