Using Server Variables
Introduction.
In any web interaction there is a large variety of
information that is passed. When a developer
wants to access this information it is usually identified by using the
name Server Variables.
This information or server variables is usually classified into two major categories
This information can be accessed within an ASP by using an appropriate Request.ServerVariables command. The names of the Server Variables are given in the following two tables. |
HTTP Header |
Description |
HTTP_ACCEPT | A list of the MIME types the client will accept |
HTTP_ACCEPT_LANGUAGE | What type of languages the browser expects. These are human languages such as en-us to represent English, United States. |
HTTP_CONNECTION | The type of connection established between the client and the web server. |
HTTP_HOST | The hostname of the web server. |
HTTP_USER_AGENT | The browser type and version, and operating system of the client. |
HTTP_REFERER | The full URL of the web page containing the hyperlink used to reach the currently executing ASP page. |
HTTP_COOKIE | The cookies sent from the browser. |
Environment Variable |
Description |
URL | The URL of the ASP page between http://www.yourWebServer.com/ and any query string. |
PATH_INFO | The same as the URL environment variable. |
PATH_TRANSLATED | The full, physical path of the currently executing ASP. |
APPL_PHYSICAL_PATH | The physical address of the web's root directory. |
QUERY_STRING | The querystring. |
SERVER_NAME | The web server's computer name. |
SERVER_SOFTWARE | The name of the web server software. |
HTTP Headers. Now we want to develop a small ASP that requests some of the HTTP headers and displays them. So you want to copy the following code into a file called SomeHTTPHeaders.asp and upload it back to your ASP web. |
<%@ Language=VBScript %> <% Option Explicit %> <html> <font size=4> <P>All of the MIME types the client will accept = <%= request.servervariables("HTTP_ACCEPT") %> </P> <P>All languages the browser accepts = <%= request.servervariables("HTTP_ACCEPT_LANGUAGE") %> </P> <P>The type of connection = <%= request.servervariables("HTTP_CONNECTION") %> </P> <P>The hostname of the client = <%= request.servervariables("HTTP_HOST") %> </P> <P>The client's type of browser and operating system = <%= request.servervariables("HTTP_USER_AGENT") %> </P> <P>The URL of the referring page = <%= request.servervariables("HTTP_REFERER") %> </P> </FONT> </html> |
The meaning of the code will be discussed in class. Now you would get something like the following screen when you view the page. |
Environment Variables.
Now we want to develop a similar ASP for displaying some important
Environment Variables. You should create a file called SomeEnvironmentVariables.asp
and copy in the following code.
|
<%@ Language=VBScript %> <% Option Explicit %> <html> <font size=4> <P>Physical path to the Webs Root Directory = <%= request.servervariables("APPL_PHYSICAL_PATH") %> </P> <P>Physical Path to the folder of the ASP that is currently running = <%= request.servervariables("PATH_TRANSLATED") %> </P> <P>The web server's computer name = <%= request.servervariables("SERVER_NAME") %> </P> <P>The web server's operating system = <%= request.servervariables("SERVER_SOFTWARE") %> </P> </FONT> </html> |
The meaning of the code will be discussed in class. You should get a screen that looks something like the following. |