ASP判断来路页面

来源:互联网 发布:淘宝网美容泛石刮沙板 编辑:程序博客网 时间:2024/05/01 02:53
<%
'来源地址
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语言的思路,其他语言的思路是一样的。
原创粉丝点击