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. ( This output is on my laptop which runs IIS on WinXP so server address is localhost or 127.0.0.1 )

ALL_HTTP :
HTTP_ACCEPT:*/* 
  
HTTP_ACCEPT_LANGUAGE:en-us 
  
HTTP_CONNECTION:Keep-Alive 
  
HTTP_HOST:127.0.0.1 
  
HTTP_REFERER:https://127.0.0.1/a/request/ 
  
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
 Trident/4.0; GTB6.6; InfoPath.2; .NET CLR 1.1.4322;
 .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) 
  
HTTP_COOKIE:__utmc=96992031; ASPSESSIONIDAQSACAQC=FHOPPKJCEMKILAHMPECCIAJJ;
 __utma=96992031.1294834349.1272246700.1286419100.1286425811.117;
 __utmz=96992031.1272246700.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=96992031 
  
HTTP_ACCEPT_ENCODING:gzip, deflate


ALL_RAW :
Accept: */* 
  
Accept-Language: en-us 
  
Connection: Keep-Alive 
  
Host: 127.0.0.1 
  
Referer: https://127.0.0.1/a/request/ 
  
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
 Trident/4.0; GTB6.6; InfoPath.2; .NET CLR 1.1.4322;
 .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) 
  
Cookie: __utmc=96992031; ASPSESSIONIDAQSACAQC=FHOPPKJCEMKILAHMPECCIAJJ;
 __utma=96992031.1294834349.1272246700.1286419100.1286425811.117;
 __utmz=96992031.1272246700.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=96992031 
  
Accept-Encoding: gzip, deflate 



APPL_MD_PATH/LM/W3SVC/1/ROOT
APPL_PHYSICAL_PATHI:\FL\
AUTH_PASSWORD
AUTH_TYPE
AUTH_USER
CERT_COOKIE
CERT_FLAGS
CERT_ISSUER
CERT_KEYSIZE
CERT_SECRETKEYSIZE
CERT_SERIALNUMBER
CERT_SERVER_ISSUER
CERT_SERVER_SUBJECT
CERT_SUBJECT
CONTENT_LENGTH0
CONTENT_TYPE
GATEWAY_INTERFACECGI/1.1
HTTPSoff
HTTPS_KEYSIZE
HTTPS_SECRETKEYSIZE
HTTPS_SERVER_ISSUER
HTTPS_SERVER_SUBJECT
INSTANCE_ID1
INSTANCE_META_PATH/LM/W3SVC/1
LOCAL_ADDR127.0.0.1
LOGON_USER
PATH_INFO/a/request/header.asp
PATH_TRANSLATEDI:\FL\a\
request\header.asp
QUERY_STRING
REMOTE_ADDR127.0.0.1
REMOTE_HOST127.0.0.1
REMOTE_USER
REQUEST_METHODGET
SCRIPT_NAME/a/request/header.asp
SERVER_NAME127.0.0.1
SERVER_PORT80
SERVER_PORT_SECURE0
SERVER_PROTOCOLHTTP/1.1
SERVER_SOFTWAREMicrosoft-IIS/5.1
URL/a/request/header.asp
HTTP_ACCEPT*/*
HTTP_ACCEPT_LANGUAGEen-us
HTTP_CONNECTIONKeep-Alive
HTTP_HOST127.0.0.1
HTTP_REFERERhttps://127.0.0.1/a/
request/
HTTP_ACCEPT_ENCODINGgzip, deflate
HTTP_USER_AGENT:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; 
Trident/4.0; GTB6.6; InfoPath.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152;
 .NET CLR 3.5.30729)
HTTP_COOKIE
__utmc=96992031;
 ASPSESSIONIDAQSACAQC=FHOPPKJCEMKILAHMPECCIAJJ; 
__utma=96992031.1294834349.1272246700.1286419100.1286425811.117;
 __utmz=96992031.1272246700.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
 __utmb=96992031

Be the first to post comment on this article :

plus2net.com




Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer