Server Side Includes

Server Side Include (SSI) commands are executed by the server as it parses your HTML file. Server side includes can be used to include the value of various server environment variables within your HTML such as the local date and time. One might use a server side include to add a signature file to an HTML file or company logo.

HTML files containing SSI must be named with an .shtml extension. Please note that HTML files containing SSI may take longer to load.

SSI commands are easy to add to your HTML, but you must follow the syntax exactly:

<!--#command cmd_argument="argument_value" -->

Be sure to leave a space after the ending quotation mark (") of the argument variable.


 

Server Side Includes

SSI Introduction
echo Command
config Command
flastmod Command
fsize Command
include Command
exec Command

Additional Sites:
NCSA HTTPd SSI's
Mark West's SSI Tutorial

Using the echo Command

The echo tag provides for inserting the data of certain variables into an HTML page. The only variable under the echo tag is 'var'. The data in an echo token is translated into a string that depends on the value in the variable and that string is inserted into the HTML page at the location of the echo token in the HTML page.

The values allowed as variable data are available form two sources: Form fields and environment variables.

Form Fields are those datum which are available when a POST operation is performed on a SSI enabled HTML document from an HTML form. Each form field may be referenced by name. Example: Suppose one has an HTML form with several fields defined, one of which is named 'First Name'. When an HTTP client POSTs the form to an SSI enabled HTML document with an echo token: <--#echo var="First Name" -->, the HTML document will then have the contents of the supplied 'First Name' field inserted upon transmission to the client.

The echo command can be used to display the content of several server/client side environment variables listed in the table below.

Variable Description

Date_Local

Current date and time (determined by server location).

Date_GMT

Current date and time in Greenwich Mean Time.

Document_Name

File name of the main document.

Document_URI

Path and file name of the main document

Last_Modified

Date and time the main document was last modified.

HTTP_COOKIE

Contains the cookie sent by the remote client, and is explained in detail.

ACCEPT_LANGUAGE

Lists the human languages that are acceptable to the remote client.

FORWARDED

The name of the proxy server through which this document is being processed

FROM

The name (most likely the email address) of the remote client user.

REFERER

The URL of the HTML document which referred the remote client to this document.

HTTP_USER_AGENT

The name of the remote client browser software.

HTTP_ACCEPT

A comma separated list of mime types that are accepted by the remote browser.

CONTENT_LENGTH

The length of the attached information in the case of a POST of PUT.

CONTENT_TYPE

The content type of the attached information in the case of a POST or PUT.

REMOTE_IDENT

The remote user name if supporting RFC931 identification.

REMOTE_HOST

The home name of the remote client.

SCRIPT_NAME

The virtual pal of the script being executed.

PATH_INFO

The extra path info as a virtual path from root directory.

REQUEST_METHOD

The method by which the current document was requested.

SERVER_PORT

The IP port the HTTP server is answering on.

SERVER_PROTOCOL

The name/version of HTTP served on the HTTP server.

GATEWAY_INTERFACE

The name/version of the CGI served on the HTTP server.

SERVER_NAME

The local computer name of the HTTP server.

SERVER_SOFTWARE

The name of the HTTP server software.

QUERY_STRING

The raw query string sent from the remote browser.

REMOTE_ADDR

IP address of the remote client browser.

Example:
Date and time determined by server location.

This code:   <!--#echo var="Date_Local" -->

will display:   Saturday, 06-May-2000 23:38:01 CST

See Using the config Command to configure the output.

Back to Top


Using the config Command

The config command can be used to configure the standard output of various environment variables. In the following example, two SSI commands are used in conjunction to produce an alternative date and time format:

Command
Command-Argument
Argument-Value
config errmsg Any ASCII text
config sizefmt Bytes of abbrev
config timefmt Any of the date codes given in the table below.

The most common use for this command is to change the date printed when using the flastmod SSI command. The flastmod SSI command prints the last modified date of a file. If you use your SSI commands to do more complex tasks, however, like executing a CGI or system command, you might find it useful to return a polite error message.

Perhaps the requested CGI program is only available to registered users. You could change the error message to return a polite I'm sorry, this function is only available to registered users instead of the rather cryptic default error message of ["an error occurred while processing this directive"].

The syntax of the config errmsg follows:

<!--#config errmsg="You can put any message here" -->

The second valid command_argument affects mainly the fsize command. It changes whether the size returned by the fsize will be returned in bytes or in a rounded-up kilobyte format. The command_argument is sizefmt, which accepts either the argument values of bytes or abbrev.

The syntax of the config sizefmt follows:

<!--#config sizefmt="bytes" --> or <!--#config sizefmt="abbrev" -->

Finally, the timefmt command argument is quite useful. You can use this inside regular text to return a date or time formatted to your preference. Whether you want only the day of the week, the current hour, or a full GMT date stamp, timefmt enables you to format the current date to fit all your needs.

Table 3.3 shows all the possible variations for the date format. It's amazing how many varieties of time are available to you.

The format for configuring the time follows:

<!--#config timefmt="Any valid grouping of format codes" -->

Format Command
Meaning
%a Abbreviated weekday name, according to the current locale
%A Full weekday name, according to the current locale
%b Abbreviated month name, according to the current locale
%B Full month name, according to the current locale
%c Preferred date and time representation for the current locale
%d Day of the month as a decimal number (ranging from 0 to 31)
%m Month as a decimal number (ranging from 10 to 12)
%U Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%W Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
%w Day of the week as a decimal, with Sunday being 0
%x Preferred date representation for the current locale without the time
%y Year as a decimal number without a century (ranging from 00 to 99)
%Y Year as a decimal number, including the century
%H Hour as a decimal number using a 24-hour clock (ranging from 00 to 23)
%I Hour as a decimal number, using a 12-hour clock (ranging from 01 to 12)
%j Day of the year as a decimal number (ranging from 001 to 366)
%M Minute as a decimal number
%p Either am or pm, according to the given time value or the corresponding strings for the current locale
%S Second as a decimal number
%X Preferred time representation for the current locale without the date
%Z Time zone, name, or abbreviation

 

This code:   <!--#config timefmt="%A, %B %d, %Y %I:%M%p" --> <!--#echo var="date_local" -->

will display:  Saturday, May 06, 2000 23:38PM

Back to Top


Using the flastmod Command

The flastmod command can be used to show the Date and time a document was last modified. Specify the path including the filename that you wish to display the last modified Date and time.

Why use this instead of <!--#echo var="Last_Modified" --> ?
The main reason is that flastmod allows you to display the modification date of a file other than the file that containing the SSI.

This code (in pageone.html):   <!--#flastmod file="/pagetwo.html" -->

will display:  Saturday, 06-May-2000 23:38:01 CST

See Using the config Command to configure the output.

Back to Top


Using the fsize Command

The fsize command might be helpful if you were to include a thumbnail image and want to display the actual file size of the original image.

e.g.   <!--#fsize file="image.gif" -->   output: 10k

Back to Top


Using the include Command

The include command can be used to include a signature file or company logo within an HTML document. The added document or image will appear as if it were part of the original document.

e.g.   <!--#include file="any.htm" -->

If the file to be included is in a different directory than the SHTML document. use the virtual command argument instead. In the following example, the SHTML document resides in a subdirectory but includes a file within account root directory:

eg.  <!--#include virtual="/any.htm" -->

Back to Top


Using the exec Command

The exec command can be used to execute a CGI script when the web page is loading. In the following example, the script test.cgi within the relative path /cgi-exec is executed.

eg.  <!--#exec cgi="/cgi-exec/test.cgi" -->

Back to Top