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") %>
上面的東東很重要:如果有這樣的網(wǎng)頁: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 那么非法
?????????????????????? 執(zhí)行“非法”指令
?????????????? 否則
??????????????????????? 執(zhí)行“合法”指令
?????????????? 結(jié)束判斷 (即:從別的頁面做個“http://www.abc.com/aaa.asp?id=8”的鏈點也不行)
否則
?????????????? 執(zhí)行“合法”指令
結(jié)束判斷。
上面用的是ASP語言的思路,其他語言的思路是一樣的。 《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
'來源地址
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") %>
上面的東東很重要:如果有這樣的網(wǎng)頁: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 那么非法
?????????????????????? 執(zhí)行“非法”指令
?????????????? 否則
??????????????????????? 執(zhí)行“合法”指令
?????????????? 結(jié)束判斷 (即:從別的頁面做個“http://www.abc.com/aaa.asp?id=8”的鏈點也不行)
否則
?????????????? 執(zhí)行“合法”指令
結(jié)束判斷。
上面用的是ASP語言的思路,其他語言的思路是一樣的。 《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
- 上一篇: 配置数据库引擎BDE(Borland D
- 下一篇: Inno Setup使用教程大全