Using CGI Variabes ColdFusion Help

CGI variables are created every time a template is requested and returned to a browser. These are a fallback to CGI-BIN programming, which was the first mechanism for server-side scripting and automation on the World Wide Web

Most Web servers including those supported by ColdFusion provide support for CGI-BIN scripts. In the world of CGI-BIN programming Web servers create a set of standard variables that are available for use in CGI-BL r scripts. Cold Fusion creates CGI variables that are available in your templates just as they would be available in CGI-BIN

These CGl variables provide information about the type of server being used the type of browser being used to request the template and other relevant information about the environment in which the template is being processed. The following list outlines the available CGI variables created by the server:

SERVER_SOFTWARE The name and version of the Web server software on which Cold- Fusion is running. This takes the form name/version.
SERVER_NAME The host name, DNS name, or IP address of the Web server.
GATEWAY_INTERFACE The version of CGI implemented by the Web server. This value takes the form CGI/ rev; s ion.
SERVER_PROTCOL The protocol and version used to request the template. This takes the form protoco 1/versi on.
SERVER]ORT The TCP /IP port on which the request for the template is received. On Wee servers, this is generally port 80.
REQUEST_METHOO The method used to request the template. With Web sell. ers, this is usually Get, Post, or possibly Head.
PATH_INFO Extra path information provided by the client.
PATH_TRANSLATED A translated version of the PATH_INFO variable converting virtual to physical paths.
SCRIPT_NAME The virtual path to the requested template.
QUERY_STRING Any query data following the question mark in the URL being used to access the template.
REMOTE_HOST The host name of the client system requesting the template. If this information is unavailable, then the variable is not set.
REMOTE_ADDR The IP address of the client system requesting the template.
AUTH_TYPE The type of authentication used to validate a user if the requested template is protected. .
REMOTE_USER The username of the client user accessing a protected template (also available as AUTH_USER).
REMOTE_IDENT The remote username retrieved from servers that support RFC 931 identification. (RFC documents are known as request for comments documents. These represent early definitions of proposed standards that are not yet fu{alized and approved by the relevant standards bodies.)
CONTENT_TYPE The content type of attached data for requests that allow attached data (such as IITTP Put and Post requests).
CONTENT_LENGTH The length in characters of content provided by the client. In addition to the variables created by the server, several variables are created by the browser and passed to the server along with the request. These are.outlined in the following list:
HTTP_REFERER The URL of the document from which a link or form submission led to the requested template.
HTIP _USER_AGENT The browser being used by the client. This takes the form software/ version library/version.
HTTP_IF_MODIFIED_SINCE This variable is used to support browser caching of documents. It indicates to the server the date of the version of a document in the cache so the server will only send newer documents to the browser.

To access CGI variables simply add CGI. to the front of any variable name outlined in the preceding two lists. For instance, the following template displays the page a user came from and the browser they are using:

You followed a link from #CGI.HTIP_REFERER#’.
You are using #CGI.HTIP_USER_AGENT#.

This produces results like those in Figure 4.l.

Notice the use of the CFIF tag. You will learn about the CFIF tag in Chapter 7, “Controlling the Flow of Your Templates.” In this example, you are testing whether HTIP _REFERER is the empty string. You do this because this variable is set only when the user follows a link to the current template or submits a form to the current template. Otherwise, the variable will be the empty string, and you want to output the first sentence only when the variable has a value



Posted on November 14, 2015 in Creating and Manipulating Variables

Share the Story

Back to Top
Share This