Server-Side Includes

Server-side includes (SSI's) are simple, HTML-embedded directives that instruct the Web server to execute a program or include data in an HTML document. As a shorthand alternative to CGI, server-side includes can be handy. However, like CGI, they should be used with caution and an eye for security risks. Since server-side includes are directives for the server, they must be parsed each time the document is delivered to a browser.

This page is a brief introduction to the Server-Side Includes supported by the LiveZone Web server. Much of this page is copied from the Stronghold Reference Manual © C2N, Inc. For a complete reference, we recommend that you refer to the original document.

An Example

The SupportZone MIME type page lists all MIME types currently known to the Web server. Using server-side includes is a quick and simple method for us to ensure that the MIME page is always up-to-date, without needing to edit the SupportZone HTML page when new types are added.

<P>This list is accurate as of <!--#echo var="DATE_LOCAL"-->.
<PRE><!--#include file="mime.types"--></PRE>

The HTML snippet above is the actual code from the MIME page that shows the current time and date, then includes the contents of the actual server configuration file that defines the MIME type extensions.

Syntax and Directives

All SSI directives follow this format:

<!--#directive parameter="value"-->

Directives can have more than one parameter, and multiple parameters are separated by white space. The valid SSI directives are as follows:

echo

Syntax: echo var="environment-variable"

Echo inserts the value of one or more SSI environment variables.

include

Syntax: include file|virtual="path"

The include directive inserts the text of another document, specified either as a file or a virtual file. Path must be relative to the current document in the case of a file, or it can be a virtual path. For example:

<!--#include file="sample.html"-->
<!--#include virtual="/virtual/sample.html"-->

fsize

Syntax: fsize file="path"

The fsize directive inserts the size of the file specified by path, in bytes. For example:

This file is <!--#fsize file="example.ps"--> bytes.

flastmod

Syntax: flastmod file="path"

Similar to fsize, flastmod inserts the modification date for the file specified by path. For example:

This file was last modified on <!--#flastmod file="example.html"-->.

config

Syntax: config errmsg|sizefmt|timefmt="string"

You can use the config directive to modify the default SSI behavior. The parameters are as follows:

errmsg: Sets the default error message. For example:

<!--#config errmsg="Error: Try again."-->

sizefmt: Sets the format for file size data returned by the fsize directive. Thestring for this parameter is either "bytes" for file sizes in bytes, or "abbrev" for file sizes rounded to the nearest kilobyte. For example:

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

timefmt: Sets the format for dates and times returned by the flastmod directive and the DATE_LOCAL and DATE_GMT variables. The possible values for this parameter are as follows:
 Format Code  Description
 %a  Abbreviated day of the week, such as "Sun" for Sunday
 %A Unabbreviated day of the week
 %b  Abbreviated month, such as "Jan" for January
 %B  Unabbreviated month
 %d Two-digit, numerical day of the month, such as "01"
 %D  Numerical month, day, and year, such as "01/24/97"
 %e Numerical day, such as "1"
 %H  24-hour clock hour, such as "17"
 %I  12-hour clock hour, such as "11"
 %j  Numerical day of the year, such as "278"
 %m  Numerical month, such as "11"
 %M Minutes, such as "08"
 %p  AM or PM
 %r Time, such as "08:23:17 AM"
 %S  Seconds, such as "56"
 %T  24-hour time, such as "23:54:56"
 %U  Week of the year, such as "47"
 %w  Numerical day of the week, such as "0" for Sunday and "7" for Saturday
 %y  Year of the current century, such as "97"
 %z  Abbreviated time zone, such as "PST"

printenv

Syntax: printenv

This directive prints a complete list of all existing SSI variables and their values. It has no attributes. For example:

<!--#printenv-->

set

Syntax: set var="variable" value="value"

This directive sets the value of an environment variable. For example:

<!--#set var="country" value="Liberia"-->

Flow Control Elements

Stronghold 2.0 implements Extended SSI, which includes flow control elements much like the ones used in programming languages. With flow control, you can create more sophisticated SSI scripts. There are four flow control elements:

<!--#if expr="test-condition"-->
<!--#elif expr="test-condition"-->
<!--#else-->
<!--#endif-->

The test-condition is one of the following:
 Test Condition  Description
string  True if the string is not empty
string1 = string2  True if string1 matches string2
string1 != string2  True if string1 does not match string2
(test-condition)  True if test-condition is true
! test-condition  True if test-condition is false
test-condition1 && test-condition2  True if both test-condition1 and test-condition2 are true
test-condition1 || test-condition2  True if either test-condition1 or test-condition2 is true

SSI Environment Variables

In a server-side include string, you can use any environment variables available to the server, including the CGI variables listed in "Environment Variables" on page 7-2. SSI also has its own environment variables, listed here.

DOCUMENT_NAME

The filename of the current HTML document. For example:

This file is called <!--#echo var="DOCUMENT_NAME"-->.

DOCUMENT_URL

The URL of the current file. For example:

This document is located at <!--#echo var="DOCUMENT_URL"-->.

QUERY_STRING_UNESCAPED

An unencoded query string whose metacharacters are escaped with a backslash (\).

DATE_LOCAL

The local date and time. For example:

Here in San Francisco, it is now <!--#echo var="DATE_LOCAL"-->.

DATE_GMT

The current Greenwich Mean Time. For example:

The current time is <!--#echo var="DATE_GMT"--> GMT.

LAST_MODIFIED

The date and time when the current file was last modified. For example:

I last modified this page on <!--#echo var="LAST_MODIFIED"-->.



www.livezone.com
   

To SupportZone Main Page

Last Updated January 2007
Copyright (c) 1995-2007 by LiveZone Communications LLC. All rights reserved.
WomenZone, BusinessZone, SupportZone are trademarks of LiveZone Communications, LLC.
LiveZone is a registered trademark of LiveZone Communications, LLC.