一段ASP的HTTP_REFERER判断代码
时间:2021-03-06 10:10:30|栏目:ASP代码|点击: 次
只要不是HTTP_REFERER来源于(google.com google.cn *.google.com *.google.cn baidu.com *.baidu.com)这些网址来源的请求,就通通转发至404
<%
Dim a, reg
a = Request.ServerVariables("HTTP_REFERER").Item
Set reg = New RegExp
reg.Pattern = "^http://(?:[^.]*\.)?(?:google\.com|google\.cn|baidu\.com)(/|$)"
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.com|google.cn|baidu.com"'排除信息
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%>
复制代码 代码如下:
<%
Dim a, reg
a = Request.ServerVariables("HTTP_REFERER").Item
Set reg = New RegExp
reg.Pattern = "^http://(?:[^.]*\.)?(?:google\.com|google\.cn|baidu\.com)(/|$)"
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.com|google.cn|baidu.com"'排除信息
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%>