一段ASP的HTTP_REFERER判断代码
编程学习 2021-07-05 10:58www.dzhlxh.cn编程入门
其实我这样做的本意是为了防止盗链!大家帮忙看一下通过代码能够根治盗链!
只要不是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%>
上一篇:asp datediff 时间相减
下一篇:asp 关键词高亮显示(不区分大小写)