14-2 讀?伺?器??變數

Request 󤺧t Request.ServerVariables XAX]tFAܼƪȡAoܼƲ[\FΤݩMAݪUظTC

ҦpAYnoΤݤΦAݪ IPAiΤUC覡oG

dҦpUG

Example]requestIp01.asp^G

WzdҪlɦpUG

lɡ]requestIp01.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥ Request.ServerVariables ӧ IP"%>
<!--#include file="head.inc"-->
<hr>

<li>HTTP request ӷ IP: Request.ServerVariables("REMOTE_ADDR") = <font color=red><%=Request.ServerVariables("REMOTE_ADDR")%></font>
<li>HTTP request A IP: Request.ServerVariables("LOCAL_ADDR") = <font color=red><%=Request.ServerVariables("LOCAL_ADDR")%></font>
<li>HTTP request NzA: Request.ServerVariables("HTTP_VIA") = <font color=red><%=Request.ServerVariables("HTTP_VIA")%></font>
<li>HTTP request lӷ IP: Request.ServerVariables("HTTP_X_FORWARDED_FOR") = <font color=red><%=Request.ServerVariables("HTTP_X_FORWARDED_FOR")%></font>

<hr>
<!--#include file="foot.inc"-->

pGAo쪺Ȥ IP äAq IPAiOAsQ]wgѥNzA]Proxy Server^ӨoA] Request.ServerVariables("REMOTE_ADDR") NܦNzA IP FCboرpUAڭ̥i Request.ServerVariables("HTTP_VIA") ܩҥΨ쪺NzAAå Request.ServerVariables("HTTP_X_FORWARDED_FOR") ouȤݪ IPCMApGAsèS]wϥΥNzAAg Request ҧ쪺ܼ Request.ServerVariables("HTTP_VIA") M Request.ServerVariables("HTTP_X_FORWARDED_FOR") uOŦrӤwC

Hint
AiH]wΨNzAAAݬݤWzdҪGO_ܤơC

@²檺ΡANOˬdӷ IPAӨMwO_ѺsCҦpApGڭ̪uWЧu}񵹲MjPǬݡAڭ̴NiHˬdlӷ IP O_ 140.114.xxx.xxxAYOAhǰeAdҦpUG

Example]requestIp02.asp^G

WzdҪlɦpUG

lɡ]requestIp02.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="s IP"%>
<!--#include file="head.inc"-->
<hr>

<%
ip=Request.ServerVariables("REMOTE_ADDR")+"";
proxy=Request.ServerVariables("HTTP_VIA")+"";
if (proxy!="undefined")		// YϥΥNzAAhlΤ IP
	ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR")+"";
Response.write("lΤ IP = " + ip + "<br>");
Response.write("Proxy = " + proxy + "<br>");
domain="140.112.";
if (ip.indexOf(domain)!=0){
	Response.write("This page is not allowed!");
	Response.end;	// ǰeI
}
%>

oOxj IP ݨ쪺`I

<hr>
<!--#include file="foot.inc"-->

Hint
bϥ ASP ɡAYnN󤺪r]wt@ӦrܼƮɡAڭ̳q`ϥΡuip=Request.ServerVariables("REMOTE_ADDR")+""v覡Apj૬A~קK] Request.ServerVariables("REMOTE_ADDR") iणO@ӦrꪫұaӪxZC

PATAiHCXpUG

dҦpUG

Example]requestServer01.asp^G

WzdҪlɦpUG

lɡ]requestServer01.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥ Request.ServerVariables ӦCXPAT"%>
<!--#include file="head.inc"-->
<hr>

<ul>
<li>AW١GRequest.ServerVariables("SERVER_NAME") = <font color=red><%=Request.ServerVariables("SERVER_NAME")%></font>
<li>A𸹡GRequest.ServerVariables("SERVER_PORT") = <font color=red><%=Request.ServerVariables("SERVER_PORT")%></font>
<li>AwGRequest.ServerVariables("SERVER_PROTOCOL") = <font color=red><%=Request.ServerVariables("SERVER_PROTOCOL")%></font>
<li>AnW١GRequest.ServerVariables("SERVER_SOFTWARE") = <font color=red><%=Request.ServerVariables("SERVER_SOFTWARE")%></font>
<li>A[KGRequest.ServerVariables("SERVER_PORT_SECURE") = <font color=red><%=Request.ServerVariables("SERVER_PORT_SECURE")%></font>
</ul>

<hr>
<!--#include file="foot.inc"-->

P|TAiHCXpUG

dҦpUG

Example]requestPath01.asp^G

WzdҪlɦpUG

lɡ]requestPath01.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥ Request.ServerVariables ӦCXP|T"%>
<!--#include file="head.inc"-->
<hr>

<ul>
<li>Aڥؿwи|GRequest.ServerVariables("APPL_PHYSICAL_PATH") = <font color=red><%=Request.ServerVariables("APPL_PHYSICAL_PATH")%></font>
<li>bwЪ|GRequest.ServerVariables("PATH_TRANSLATED") = <font color=red><%=Request.ServerVariables("PATH_TRANSLATED")%></font>
<li>۹Aڥؿ|GRequest.ServerVariables("PATH_INFO") = <font color=red><%=Request.ServerVariables("PATH_INFO")%></font>
<li>۹Aڥؿ|GRequest.ServerVariables("SCRIPT_NAME") = <font color=red><%=Request.ServerVariables("SCRIPT_NAME")%></font>
<li>۹Aڥؿ|GRequest.ServerVariables("URL") = <font color=red><%=Request.ServerVariables("URL")%></font>
</ul>

<hr>
<!--#include file="foot.inc"-->

bWzdҤARequest.ServerVariables("PATH_INFO")BRequest.ServerVariables("SCRIPT_NAME") M Request.ServerVariables("URL") |^Ǥ@˪GC

LΪT]iH Request.ServerVariables oAҦpG

dҦpUG

Example]requestHttpReferer01.asp^G

WzdҪlɦpUG

lɡ]requestHttpReferer01.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥ Request.ServerVariables ӧusܥثee@Ӻv"%>
<!--#include file="head.inc"-->
<hr>

<ul>
<li>sܥثee@ӺGRequest.ServerVariables("HTTP_REFERER") = <font color=red><%=Request.ServerVariables("HTTP_REFERER")%></font>
<li>ΤݩҥΪsGRequest.ServerVariables("HTTP_USER_AGENT") = <font color=red><%=Request.ServerVariables("HTTP_USER_AGENT")%></font>
<li>ΤݵnܺbGRequest.ServerVariables("LOGON_USER") = <font color=red><%=Request.ServerVariables("LOGON_USER")%></font>
</ul>

<hr>
<!--#include file="foot.inc"-->

ϥ Request.ServerVariables("HTTP_REFERER")AAiHoUCƶG

YN Request.ServerVariables ҦܼƤ@LXAiUCdҡG

Example]request/serverVariables.asp^G

WzdҪlɦpUG

lɡ]request/serverVariables.asp^G]ǦϰUYi^
<%@ language="jscript" %>
<% title="CX Request.ServerVariables" %>
<!--#include file="../head.inc"-->
<hr>

<!--#include file="../listdict.inc"-->
<% listdict(Request.ServerVariables, "Request.ServerVariables"); %>

<hr>
<!--#include file="../foot.inc"-->

lɥ]tF listdict.incAlɮצpUG

lɡ]listdict.inc^G]ǦϰUYi^
<script runat=server language=jscript>
function listdict(dict, dictname){
	Response.Write("<table border=1 align=center>\n");
	Response.Write("<tr><th colspan=2 bgcolor=cyan>" + dictname + "\n");
	Response.Write("<tr><th>Names<th>Values\n");
	var Enum=new Enumerator(dict);
	for (Enum.moveFirst(); !Enum.atEnd(); Enum.moveNext()){
		Response.Write("<tr><td>");
		Response.Write(dictname+"(\""+Enum.item()+"\")\n");
		Response.Write("<td>");
		Response.Write(dict(Enum.item())+"&nbsp;");
	}
	Response.write("</table>\n");
}
</script>

<script runat=server language=vbscript>
function listdict(dict, dictname)
	dim key
	response.write("<table border=1 align=center>" & vbcrlf)
	response.write("<tr><th colspan=2 bgcolor=cyan>" & dictname & vbcrlf)
	response.write("<tr><th>Names<th>Values" & vbcrlf)
	For Each key in dict
		response.write("<tr>" & newline)
		response.write("<td>" & dictname & "(""" & key & """)</td>")
		response.write("<td>&nbsp;" & dict(key) & "</td>")
		response.write("</tr>" & vbcrlf)
	next
	response.write("</table>" & vbcrlf)
end function
</script>

listdict.inc ]tӨơAOΩI JScript M VBScriptAiCLX Dictionary ܼơAҦpWzdҪ Request.ServerVariablesCb JScript listdict() ƤAڭ̥ΨF Enumerator AO VBScript Dictionary ܼơAiΦrӯޥt@ӦrC

YnD Request.ServerVariables ҥ]tܼƪNqAiHdݤUCG

http://www.devguru.com/index.asp?page=/technologies/asp/quickref/request_servervariables.html
AѨõγoǦAܼơAiϩp Web {]pƥb\C

WzLҦ Request.ServerVariables kAO JScript ӹFAڭ̤]iHϥ VBScript ӹFۦP\AШdҵ{Xuexample/request/serverVariables_vbs.aspvA{X]]tFۦP listdict.incAHKCXҦAܼơC


JScript {]pPΡGΩAݪ ASP