一段ASP的HTTP_REFERER判断代码

只要不是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%>

若文章对您有帮助,帮忙点个赞!

0
2
发布时间 2009-03-12 02:09:36
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)