20.2 How to Read the Value of a HTTP Header?

To read the value of a HTTP header, you need to use a server-side technology like ASP, Java Servlet, JSP, Perl, PHP, etc.

For example, to read the user-agent header value and store it into a variable uaheader with JSP, use the following code:


String uaheader = request.getHeader("user-agent");


For ASP (VBScript), use the following code to read the user-agent header value:


dim uaheader
uaheader = Request.ServerVariables("http_user_agent")


For ASP (JScript), use the following code to read the user-agent header value:


var uaheader = Request.ServerVariables("http_user_agent");


For PHP, use the following code to read the user-agent header value:


$uaheader = $_SERVER["HTTP_USER_AGENT"];


Previous Page Page 38 of 39 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.