ASP http_referer, SERVER_NAME, and http_host

Source: Internet
Author: User
Tags servervariables

Just run a SectionCodeTo view the number of values in request. servervariables. A total of 50 values are available!
Code <% = request. servervariables. Count %>
In the past, I felt that there were a lot of values in request. servervariables, but now there are still so many values, but today I will talk about one of the values ---- http_referer
First, we first know that the most common application of http_referer is to prevent external submissions.

Request. servervariables ("http_referer") is obtained normally from the address bar of the browser in the following cases "):
1) directly use <a href = "">
2) form submitted with submit or <input type = "image"> (post or get)
3) form submitted using JavaScript (post or get)

Next let's take a look at the situations where the request. servervariables ("http_referer") cannot be set properly:
1) link from favorites
2) Click the home page or custom address
3) directly enter the address in the browser
4) use JavaScript location. href or location. Replace ()
5) <% response. Redirect %>
6) <% response. addheader %> or <mete http-equiv = "refresh"> redirect
7) load the address in XML

Obviously, request. servervariables ("http_referer") cannot work normally in most cases. For more information, seeArticleAnd 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 do not take a closer look, you cannot see the differences between them. I searched a lot on the Internet and still did not understand it. However, there is still a clear sentence: http_host can request non-80 server_port, simply put, http_host = SERVER_NAME: server_port.

I have previously published an article on the role of http_referer. Now I can use it to write an ASP function to prevent external submissions.

Copy code The Code is 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 code for execution, you can use the SELECT statement:

Copy code The Code is 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 select

The working principle of the above Code: first, we need a simple expression (often a variable), and this expression will be evaluated once. Then, the expression value is compared with the value in each case. If the expression matches, the code corresponding to the matched case is executed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.