Using Server Side Includes

Specifically for use on www.morris.umn.edu,
but applicable at any site using standard include syntax.

[ Overview | Creating a SSI Document | Using SSI Directives ]
[ SSI Directives | SSI Environment Variables ]

Overview
Server Side Includes (SSI) allow dynamically changing web pages to be created. SSI can be as simple as inserting the current time or another text file into a web page and powerful enough to include the output of commands or cgi programs. Basically, SSI allow a degree of flexibility that is unatainable with static html documents. That flexibility comes at a cost of increasing the server load, so please make an effort to use SSI responsibly. Avoid on the fly
Povray renderings for example :-) For your information, SSI were first popularized in the NSCA, httpd webserver, and much of this information comes from the NCSA SSI tutorial.

Step 1: Create the HTML file that will use SSI
On www.morris.umn.edu, files that use SSI, need to end with the suffix .shtml, e.g. index.shtml. This specific suffix tells the web server to parse the file each time it is viewed and process the SSI directives. If you are adding SSI to an existing web page, you can just rename the previous file to end with .shtml ("mv index.html index.shtml", would be the appropriate unix command).

Step 2: Add the SSI directives to the HTML file
SSI directives are formatted as HTML comments. For example,

<!--#echo var=DATE_LOCAL-->
will insert the current local time
(none)

include inserts a file into the web page. All access permissions still apply to the file and file includes are recursive, so SSI directives in the included file will be processed also. The include directive accepts either a "virtual" or a "file" argument. virtual is a virtual path from the document root of the webserver. file is a path to a file that is relative to the current document. file doesn't allow ../ or full paths, e.g. /dir /file, to be used.

Format: <!--#include [virtual | file]="some_file"-->
Example: <!--#include file="sample.txt"-->
Result: This is the content of sample.txt

exec places the output of a command into the web page. The two possible arguments to the exec directive are cmd and cgi. cmd will use the sh shell to run the command. cgi will execute the given virtual path to a cgi script and return the output

Format: <!--#exec [cmd | cgi] = "executable program"-->
Example: <!--#exec cmd="uptime"-->
Result: 08:37:06 up 6 days, 2:01, 3 users, load average: 0.25, 0.23, 0.19

flastmod prints the last modification date of a file. The arguments that can be used are the same as for the include directive. The output formatting is set by the timefmt config parameter.

Format: <!--#flastmod [virtual | file] = "filename"-->
Example: <!--#flastmod file="ssi.shtml"-->
Result: Monday, 22-Aug-2005 13:20:54 CDT

fsize prints the size of a file. The arguments that can be used are the same as for the include directive. The output formatting is set by the sizefmt config parameter.

Format: <!--#fsize [virtual | file] = "filename"-->
Example: <!--#fsize virtual="/index.html"-->
Result: [an error occurred while processing this directive]

config controls various aspects of parsing and the formatting of certain information. There are three possible arguments:

  • errmsg controls what message is sent back to the client if an error includes while parsing the document. When an error occurs, it is logged in the server's error log.
  • timefmt gives the server a new format to use when providing dates. This is a string compatible with the strftime library call under most versions of UNIX (the command "man strftime" will show the information).
  • sizefmt determines the formatting to be used when displaying the size of a file. Valid choices are:
    • bytes - for a formatted byte count (formatted as 1,234,567)
    • abbrev - for an abbreviated version displaying the number of kilobytes or megabytes the file occupies.
Format: <!--#config argument="value"-->
Example: <!--#config timefmt="%A, %B %d, %Y"-->
Result: Displays the date as Wednesday, November 25, 2009
instead of the default Wed Nov 25 08:37:06 CST 2009

SSI Environment Variables
The following variables are available for the echo SSI directive to access in addition to the standard CGI environment variable set. Look at the complete list of
environment variables for more information.

[ Campus Homepage | WWW Advisory Group Homepage | Web Toolbox ]


The University of Minnesota is an equal opportunity educator and employer.

The UMM WWW Page -- University of Minnesota, Morris
Copyright 1996 University of Minnesota, Morris
Last Updated: January 8, 1996
Page URL: http://www.morris.umn.edu/committees/wwwac/toolbox/ssi.shtml

Please e-mail questions or comments to:
Nancy Mooney - Group Chair or
The entire UMM WWW Advisory Group