18.4. Using Environment VariablesIn the example in the previous section, the information placed in the document was prepared ahead of time and saved in a file on the server for future use. Another type of information that can be used by an SSI element is environment variables. These are bits of information that the operating system (or the HTTP server) always keeps track of and makes available for use by CGI programs and SSI. The current date and time, the modification times of local files, and the user's browser version are all examples of environment variables. To use one in an SSI, call it by its specific variable name (DATE_LOCAL, LAST_MODIFIED, and HTTP_USER_AGENT, respectively, for the previous examples) in the command. Note that variable names can vary for different server software. The complete list is available under Section 18.7, "Include Variables" later in this chapter. 18.4.1. Example: Printing the Date and TimeLet's look at a very simple example of how environment variables work. In the following example, we'll display the current date and time on the web page using the echo element (which prints a specified variable to the screen) and the DATE_LOCAL variable. If I put the following SSI command in my HTML source: <!--#echo var="DATE_LOCAL" --> the server prints the following in its place: Thursday, 28-Apr-01 16:39:24 EST
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|