10 server variables you need to know to create dynamic web pages

Each time you request a web page, there is a lot of activity going on in the background: your request is sent to a DNS server, the IP address is found, the appropriate web server is contacted, the return stream is decoded, and your web browser generates an HTML page. In addition to the request for the actual HTML content, the web server includes a number of important “server variables” in its response. These variables contain information about the Web server environment – its name, IP address, and software – as well as the current script execution environment – the script name and path, and the query strings.

These variables are often used by smart web developers to increase script dynamics and stability. Here is a brief list of 10 more useful server variables that web servers typically send in response to HTTP requests, and this table will also tell you when and how to use them on your web site.

Note: Not all of these variables are available on all web servers.

Variables
Description
Purpose

HTTP_USER_AGENT
The identity string sent by the requesting client. For example: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5.
Client detection and login; create different codes for different “browsers”.

HTTP_ACCEPT_ENCODING
List of encodings that the client can decode.
For example, use the GZIP encoding program to compress page data to increase the speed of transmission.

REMOTE_ADDR
The IP address of the client sending the request.
Get the user’s geographic location for targeted advertising or localized information fetching; restrict access to specific IP addresses or groups of IP addresses.

DOCUMENT_ROOT
The root directory of the server document (defined in the configuration file).
Create relative/absolute paths when uploading, copying, or moving files through a web application.

SERVER_SOFTWARE
The signature of the server to indicate the name and version of the server, and all software running on it. For example: Apache/2.0.55 (Win32).
The ability to identify the server.

QUERY_STRING
A list of variable-value pairs followed by “?” in the requested URL. followed by a list of variable-value pairs.
Retrieves or analyzes the variable-value pairs sent to the server via the URL.

REQUEST_METHOD
This method is used to make a URL request. For example: GET, POST or PUT.
Identifies the method used to request the page and accesses the corresponding namespace used for variable fetching.

SCRIPT_NAME
The server path of the requested resource (as opposed to the root of the document).
Fetches the name and path of the currently executing script or resource.

HTTP_ACCEPT_CHARSET
The character set that can be received by the client.
Sends page data in the preferred character set.

REMOTE_USER
The user name used for authentication when using HTTP authentication.
Content personalization; authentication of the trust certificate.

Leave a Reply

Your email address will not be published. Required fields are marked *