[CSM CGI Main Menu] [Application: http://www.students.mines.edu/setup/] [Examples: http://www.students.mines.edu/examples/] [Guidelines: http://www.students.mines.edu/setup/guidelines.shtml] [CSM Home: http://www.mines.edu/] [CGI Home: http://www.students.mines.edu/]
[SSI Examples]

Server Side Includes (SSI's)


SSI Introduction

SSI's (Server Side Includes) allows users to create documents which provide basic and complex information to clients on the fly. Such information can include the current date, the file's last modification date, and the size or last modification of other files. In its more advanced usage, it can provide a powerful interface to CGI and /bin/sh programs. These commands are placed directly in the HTML document, and don't necessairly require any additional files or programs.

A useful source of information about SSI's is from NCSA:

NCSA HTTPD Server Side Includes (SSI)
One of the most important parts of using SSI's on our server, is that an HTML file containing a SSI command must have a *.shtml filename extension. If SSI commands are contained within a document, and this extension is not used, the client will receive an error message. This extension (*.shtml) tells the server that there are SSI instructions in the file, and that the file cannot simply be sent to the requesting client. Most likely, one or more commands will have to be executed, and the contents of the HTML document will be modified. The *.shtml extension should not be used on files without SSI commands, because SSI documents take slightly longer to serve, because the web server must examine, and process what is sent.
WARNING: Care needs to be taken when editting these files. Using built in browser editors, such as Netscape or Internet Explorer, will distroy the SSI document. These browser/editors download the displayed/served document. The contents of this document may have been dynamically generated based on the SSI commands. The SSI commands themselves though are NOT included if the final document sent to the client. If the version of the page the client receives, is published back to the server, the SSI commands will be lost, and the document will become a static document.

SSI Format

All directives to the server are formatted as SGML comments within the document. This is in case the document should ever find itself in the client's hands unparsed. Each directive has the following format:

<!--#command tag1="value1" tag2="value2" -->
Each command takes different arguments, most only accept one tag at a time. The entire command generally most be complete on a single line; line breaks within the command are not acceptable.


Example SSI In-Line Commands

Using the following commands the following tasks can be performed:

  1. config: this directive controls various aspects of the file parsing. The two valid tags are timefmt and sizefmt. Examples will be shown in the echo and fsize sections below.

  2. include: prints the value of one of the include variables. Any dates are printed subject to the currently configured timefmt. The only valid tag to this command is var, whose value is the name of the variable you wish to echo.

    Note: the include file must reside in the same directory as the file being served. If the same file is to be used for multiple pages in multiple directories, make a master file, and place it in each directory using symbolic links.

  3. echo: prints the value of one of the include variables. Any dates are printed subject to the currently configured timefmt. The only valid tag to this command is var, whose value is the name of the variable you wish to echo.

  4. fsize: prints the size of the specified file. The resulting format of this command is subject to the sizefmt parameter to the config command.

  5. flastmod: prints the last modification date of the specified file, subject to the formatting preference given by the timefmt parameter to the config command.

  6. exec: executes a given shell command or CGI script. It must be activated to be used.

    Note: <pre> and </pre> tags were placed around the SSI command, otherwise the results of the ls -asl command would have been printed on a single line.


Portions of this document have been directly exerpted from NCSA HTTPD Tutorial on SSI's (see link at top of page).


Comments to webmaster@mines.edu
<i>March 1998</i>