asp限制域名訪問實現程式碼
阿新 • • 發佈:2020-09-15
asp 設定只能指定域名可以使用此網站
程式碼一 我們原創
<% myIp = ",127.0.0.1,localhost,www.jb51.net," myurl= request.ServerVariables("SERVER_NAME") Response.write myurl if InStr(myIp,","&myurl&",")>0 then Response.write "域名合法" else Response.write "域名不合法" end if %>
程式碼二
myIp = Array("127.0.0.1","jb51") myHou = new Array("",".com") myDirect ="//www.jb51.net/" ip= request.ServerVariables("HTTP_HOST") j=0 for i=0 to ubound(myIp) 'Response.Write(i&"--"&myIp(i)&"<br>") if InStr(ip,myIp(i)&myHou(i))>0 then 'Response.Write(myIp(i)&"==") j=j+1 end if next if j<1 then response.Redirect(myDirect) end if
上面的程式碼用到了下面的資料
asp獲取當前域名和埠號方法
asp獲取當前域名從來就不是什麼有難度的事情,但是在實際專案使用中,大家獲取的具體URL資訊可能是不同的,各個方法獲取見下表,而如果要獲取當前域名,可以看下面加粗部分:
Request.ServerVariables("SERVER_NAME")'當前域名
Request.ServerVariables("SERVER_PORT")'當前埠
Request.ServerVariables("SCRIPT_NAME")'當前檔名
Request.ServerVariables("QUERY_STRING")'當前頁面的傳入引數
Request.ServerVariables("HTTP_USER_AGENT")'取得當前瀏覽器資訊Request("remote_addr")'取得IP
Request.ServerVariables("HTTP_REFERER")'上個頁面地址
Request.ServerVariables("HTTP_HOST")'獲取當前域名
當採用SERVER_NAME時返回的是不帶埠號的URL