Using Environment Variables
In 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 later in this chapter.
Example: Printing the Date and Time
Let’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
Tip
If the date and time format looks a little dry to you, you can change
it using the config element and SSI time formats
as explained later in this chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access