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.C ’設置(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 %>? 圖片防盜鏈代碼在CSS中添加以下代
碼: 程序代碼img {filter:expression(this.不能去掉 ? "" :((!this.complete) ? "" :this.runtimeStyle.filter = ("progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
this.src + "')") +String(this.不能去掉 = true).substr(0, 0) +(this.src = "http://www.5x5y.cn/blog/logo.gif").substr(0, 0)));}
?
總結
以上是生活随笔為你收集整理的asp下载防盗链代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP中时间格式转换
- 下一篇: ASP内置对象Request的Serve