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:220.127.116.11) Gecko/20061025 Firefox/18.104.22.168
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>:"
The above code will display all header names and its values one by one. ( This output is on my laptop which runs IIS on WinXP so server address is localhost or 127.0.0.1 )