Header data
Getting all the header data of browser by using Request object ServerVariable in ASP
When ever browser send request for a page to the server, along with the URL some more information also the browser provides to the server. This additional header information can be collected at the server end. Same way while sending back the content of the page requested by the browser the server sends some more header information back to it. All these header information can be collected at different ends and used in our scripts. We can access these HTTP header information’s and accordingly modify the content at server end. For example we need to display a different pages for different languages. By reading the header information on HTTP_USER_AGENT we can find out what is the language setting of the client browser and then redirect to that particular language page of the user.
To get the http headers we will be using ServerVariables collection of Request object in ASP. To display the value of a particular header we have to use the header name like this .
The above line will display the client browser details, with language settings etc. Here is one sample output for Firefox browser at client side.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8
We can display all the header information in one go without calling one by one by using its name. Here we have to use ALL_RAW
If we need formatted output with the list of headers (name ) then we have to use ALL_HTTP
We can display all the name value pairs for all the header information like this
For Each var in Request.ServerVariables
Response.Write “<B>” & var & “</B>:”
Response.Write Request.ServerVariables(var)
Response.Write “<br>”
Next
The above code will display all header names and its values one by one.
How to get IP address of the visitor browser in ASP
We can collect IP address of the visitor by using Request object and its ServerVariable pairs. IP address of the user is required in many applications for different purposes. IP address are collected and logged for security purposes on different occasions like credit card process, member signup time etc. From the IP address we can identify the location of the visitor. However we will restrict ourselves only to know how to collect IP address of the visitor browser from the HTTP header information.
Getting the page referrer from header information in ASP
Visitors come to different pages of a site or move from one site to other by clicking links. When they arrive at a page, we can collect the URL of the referrer page ( the page which has send them here ) by using the Request object and its ServerVariable pairs.
By using referrer once we can know how many visitors are coming from google or from other search engines and what are the keywords they are using.
In PHP we can get the referrer URL and details are here.
In ASP we will collect the http header information to get the referrer. Note that if some one has typed the page name in address bar and reached the page then referrer information will not be there. Referrer information along with some other data are used for logging or tracking the visitors.
We will use http header name HTTP_REFERER to get the URL ( site address ) of the referrer . Here is the code.
Some browsers have settings to manage the header information. This way one of the important header referrer header information can be blocked. For Firefox browser at the address bar type about:config and browse through the settings, select and change the values if you want. ( be warned to change the settings , and read all the guidelines and read in details from Mozilla and other resources )
network.http.sendRefererHeader
The above header is to be made to 2 if referrer is to be send through header