I used to feel that there were many values in Request.ServerVariables, but now I see there are still so many, but today I will talk about one of the values - HTTP_Referer and what is the difference between Server_Name and Http_Host in Request.ServerVariables?
I just ran a piece of code to see how many values there are in Request.ServerVariables. I looked at it and found 50 in total!
Code<%=Request.ServerVariables.count%>
I used to feel that there were a lot of values in Request.ServerVariables, but now I see there are still so many, but today I will talk about one of the values ---- HTTP_Referer
First of all, we first know that the most commonly used application of HTTP_Referer is to prevent external submissions.
In the following situations, Request.ServerVariables(HTTP_REFERER) is obtained normally from the browser's address bar:
1) Use <a href=> directly
2) Form submitted with Submit or <input type=image> (POST or GET)
3) Form submission using JavaScript (POST or GET)
Let's take a look at the situation where Request.ServerVariables(HTTP_REFERER) cannot take the value normally:
1) Link from favorites
2) Click on the homepage or customized address
3) Enter the address directly into the browser
4) Use JavaScript’s Location.href or Location.replace()
5) <%Response.Redirect%>
6) <%Response.AddHeader%> or <mete http-equiv=refresh> redirect
7) Load address using XML
Obviously, Request.ServerVariables(HTTP_REFERER) does not work properly in most cases. I will introduce its specific usage in detail in future articles, and also introduce the differences between Request.ServerVariables(HTTP_HOST)Request.ServerVariables(SERVER_NAME).
stay tuned!
What is the difference between Server_Name and Http_Host in Request.ServerVariables?
If you don't look closely, you shouldn't be able to tell the difference between them. I searched a lot on the Internet, but I still didn't understand it, but in the end there was a sentence that was very clear: Http_Host can request a Server_Port other than 80. Simply put, Http_Host=Server_Name:Server_Port.
I have published an article about the role of Http_Referer before, and now I will combine it to write an ASP function that prevents external submissions.
Copy the code as follows:function ChkPost()
dim server_v1,server_v2
chkpost=false
server_v1=Cstr(Request.ServerVariables(HTTP_REFERER))
server_v2=Cstr(Request.ServerVariables(SERVER_NAME))
If Mid(server_v1,8,Len(server_v2)) <>server_v2 then
chkpost=False
else
chkpost=True
end If
end function
Select Case
If you want to select one of multiple sets of codes to execute, you can use the SELECT statement:
Copy the code as follows:
select case payment
case Cash
msgbox You are going to pay cash
case Visa
msgbox You are going to pay with visa
case AmEx
msgbox You are going to pay with American Express
case Else
msgbox Unknown method of payment
end
Howthe select
code above works: First, we need a simple expression (usually a variable), and this expression will be evaluated once. Then, the value of the expression is compared with the value in each case, and if there is a match, the code corresponding to the matched case is executed.