ASP判断来路页面

<%
'来源地址
come=Request.ServerVariables("HTTP_REFERER")
url=Request.ServerVariables("server_name")
if come <> "" then
come=replace(come,"/","/")
come=replace(lcase(come)," http://","")
come=split(come,"/")(0)
come=split(come,":")(0)
else
Response.Write("不能直接下载,必须从本站链接才可以进行下载<br><br>")
Response.Write("进入站点首页:<a href=http://"&url&">"&url&"</a>")
Response.end
end if
if cstr(come)=cstr(url) then
Response.Redirect("")
else
Response.Write("链接来自:<a href=http://"&url&">"&url&"</a>")
end if
%>
<%
 function checkisUrl(tmpString)
      dim c,i
      checkisUrl = true
      tmpString=Lcase(trim(tmpString))
      if left(tmpString,7)<>"http://" then tmpString=" http://"&tmpString
      for i = 8 to Len(checkisUrl)
            c = Lcase(Mid(tmpString, i, 1))
            if InStr("abcdefghijklmnopqrstuvwxyz_-.//", c) <= 0 and not IsNumeric(c) then
                  checkisUrl = false
                  exit function
            end if
      next
      if Left(tmpString, 1) = "." or Right(tmpString, 1) = "." then
            checkisUrl = false
            exit function
      end if
      if InStr(tmpString, ".") <= 0 then
            checkisUrl = false
            response.Write "f3"
            exit function
      end if
      if InStr(checkisUrl, "..") > 0 then
            checkisUrl = false
      end if
end function
%>
<%
if checkisUrl(request("u"))=true then
      %>恭喜,你的URL通过!
%>
页面来路:
< %=Request.ServerVariables("HTTP_REFERER") %>

上面的东东很重要:如果有这样的网页:http://www.abc.com/aaa.asp?id=7,那么,我以后可以直接在浏览器中键入http://www.abc.com/aaa.asp?id=7或http://www.abc.com/aaa.asp?id=8 等等,那么就没有什么保密而言了。加上面那句判断就OK了:如果Request.ServerVariables("HTTP_REFERER")=空 则非法!再加上主机名字符是否存在的判断,就更完美了。思路如下:

如果 Request.ServerVariables("HTTP_REFERER")<>"" 那么
               如果 instr(Request.ServerVariables("HTTP_REFERER"),"主机域名")<1 那么非法
                       执行“非法”指令
               否则
                        执行“合法”指令
               结束判断 (即:从别的页面做个“http://www.abc.com/aaa.asp?id=8”的链点也不行)
否则
               执行“合法”指令
结束判断。

上面用的是ASP语言的思路,其他语言的思路是一样的。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值