asp下載防盜鏈代碼_應用技巧

來源:互聯網
上載者:User
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 and mid(From_url,8,len(Serv_url))<>"ITstudy.cn" and mid(From_url,8,len(Serv_url))<>"www.ITstudy.cn" then  
response.write "您下載的軟體來自IT學習網,請直接從首頁下載,謝謝<br>" '防止盜鏈  
response.write "<a href=http://www.ITstudy.cn>IT學習網http://www.ITstudy.cn</a>" '防止盜鏈  
response.end  
end if  
%> 

第二種:  
複製代碼 代碼如下:
<%   
  '定義函數,用ADODB.Stream讀取位元據   
  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"))'就是你讀取存在本地的檔案,防止被  
別人知道真實路徑盜連的。   
  %>  

(1)下面的樣本將 ContentType 屬性設定為其他的常見值。  
  text/HTML 這個就不說了  
  image/GIF gif圖片  
  image/JPEG jpg圖片  
  application/x-cdf cdf文檔  
  application/wma 就是西瓜哪個音樂類型了  
  具體可以參照 Web 瀏覽器文檔或當前的 HTTP 規格說明  
  這樣再利用asp的儲存session,cookies,以及讀取HTTP頭等特殊功能就可以完全真正的實現防盜連,這裡 
沒有設定緩衝,如果訪問量巨大,我想設定下就會更好吧。  
第三種: 
最簡單的用Active Server Pages防站外提交表單、跨站提交表單、防盜鏈…… 
方法:Request.SeverVariables("HTTP_REFERER") 
解釋:當某人通過連結到達當前頁,HTTP_REFERER 就儲存了這個使用者的來源(來路) 
舉個例子,這個例子很簡單,只是拋磚引玉而已,大家可以增加更多的功能。 
如下,只有首先從“ http://www.ITstudy.cn”登陸才能看到檔案內容。 
源碼:index.asp  
複製代碼 代碼如下:
<html>  
<head><title>最簡單的用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&"訪問才能進來!")  
 End if  
End Function  
%>  
<%  
Sub main()  
 Response.write("這兒是你要顯示的網頁內容")  
End sub  
%>  
</body>  
</html> 

該方法對防止盜鏈文章、站外提交表單、跨站提交表單還比較有效,對於軟體盜鏈比如.rar.zip.exe等倒沒什麼作用。 
不知各位讀者是否有好的主意,呵呵。  
還有一種方法就是用判斷伺服器及上一頁的地址來完成。 
複製代碼 代碼如下:
<%  
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  
%> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.