一段ASP的HTTP_REFERER判断代码
程序员文章站
2024-02-04 16:50:28
只要不是http_referer来源于(google.com google.cn *.google.com *.google.cn baidu.com *.baidu.co...
只要不是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%>