一段ASP的HTTP_REFERER判断代码

网络编程 2021-07-05 10:58www.168986.cn编程入门
其实我这样做的本意是为了防止盗链!大家帮忙看一下通过代码能够根治盗链!
只要不是HTTP_REFERER来源于(google. google. .google. .google. baidu. .baidu.)这些网址来源的请求,就通通转发至404
代码如下:

<%
Dim a, reg
a = Request.ServerVariables("HTTP_REFERER").Item

Set reg = New RegExp
reg.Pattern = "^http://(?:[^.]\.)?(?:google\.|google\.|baidu\.)(/|$)"
reg.IgnoreCase = True


If Not reg.Test(a) Then
Set reg = Nothing
Response.Status = "404 File Not Found."
Response.End
End If
Set reg = Nothing



' .... 继续
%>


代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Dim OK_URL,URL,HTTP_REFERER
'自定义需要过滤的字串,用 "|" 分隔

OK_URL= "google.|google.|baidu."'排除信息
OK_URL= split(OK_URL,"|") '分割排除信息
URL="404.htm" '设定指向页面
HTTP_REFERER=Request.ServerVariables("HTTP_REFERER")'获取来源网址
If HTTP_REFERER<>"" Then
For Each REFERER In HTTP_REFERER
For i=0 To Ubound(OK_URL)
If Instr(LCase(HTTP_REFERER(REFERER)),OK_URL(i))=0 Then'如果来源网址不是以上排除项的话,那就直接返回所指向的网页!
Response.Redirect(URL):Response.End()
End if

Next
Next
End If%>

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by