SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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 .

<%= Request.ServerVariables("HTTP_USER_AGENT")%>


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

<%= Request.ServerVariables("ALL_RAW")%>


If we need formatted output with the list of headers (name ) then we have to use ALL_HTTP

<%= Request.ServerVariables("ALL_HTTP")%>


We can display all the name value pairs for all the header information like this

Dim var
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.
Further readings
Collecting header information by using Request object in ASP
Collecting IP address of visitor from header data in ASP
Logging Referrer URL of a page in ASP
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.