Server Side Includes

Server Side Includes (SSI) are a primitive scripting language. Since the advent of JSP, ASP, PHP and JavaScript, SSI scripting has faded away. It is still used to include files and to display the modification times of files.

Sections that will be covered in the exam have headings that look like this.

Special SSI Variables Available to the echo command

LAST_MODIFIED
Last modified on
Last modified on <!--#echo var="LAST_MODIFIED"-->
DOCUMENT_NAME
The document name is
The document name is <!--#echo var="DOCUMENT_NAME"-->
DOCUMENT_URI
The document URI is
The document URI is <!--#echo var="DOCUMENT_URI"-->
DATE_GMT
The GMT date is
The GMT date is <!--#echo var="DATE_GMT"-->
DATE_LOCAL
The local date is
The local date is <!--#echo var="DATE_LOCAL"-->

All Environment Variables are also Available

HTTP_USER_AGENT
The user agent is
The user agent is <!--#echo var="HTTP_USER_AGENT"-->
HTTP_HOST
The http host is
The http host is <!--#echo var="HTTP_HOST"-->
SERVER_NAME
The server name is
The server name is <!--#echo var="SERVER_NAME"-->
HTTP_ACCEPT
Http accept is
Http accept is <!--#echo var="HTTP_ACCEPT"-->
HTTP_ACCEPT_LANGUAGE
Http accept language is
Http accept language is <!--#echo var="HTTP_ACCEPT_LANGUAGE"-->

Including Files

Here is the file that I include in my class pages.
Relative references are relative to the current directory.
Absolute references are relative to the document root.
Relative references use the file attribute: <!--#include file="menu.htm" -->

Absolute references use the virtual attribute: <!--#include virtual="/includes/menu.htm" -->

Creating Local Variables

It is possible to create a local variable inside a file that uses SSI commands.

Set a variable

<!--#set var="fiu" value="www.fiu.edu" -->
Echo a variable
The value of fiu is
The value of fiu is <!--#echo var="fiu" -->

Size and Last Modified of a file

Last Modified.
Relative references are relative to the current directory.
Absolute references are relative to the document root.
Relative reference: Last modified on <!--#flastmod file="menu.htm" -->
Last modified on

Absolute reference: Last modified on <!--#flastmod virtual="/includes/menu.htm" -->
Last modified on
File Size
Relative references are relative to the current directory.
Absolute references are relative to the document root.
Relative reference: File size in K <!--#fsize file="menu.htm" -->
File size in K

Absolute reference: File size in K <!--#fsize virtual="includes/menu.htm" -->
File size in K

Change the format of the output

For a list of the time formatting codes, visit this site: http://internetconnection.net/support/tech-ssitime.html

Change the last modified date to m/d/y, the decimal number day of the year, and am/pm
<!--#config timefmt="%A %D (day %j) at %r" -->

Change the file size to bytes
<!--#config sizefmt="bytes" -->

Last Modified
Relative references are relative to the current directory.
Absolute references are relative to the document root.
Relative reference: Last modified on <!--#flastmod file="menu.htm" -->
Last modified on

Absolute reference: Last modified on <!--#flastmod virtual="/includes/menu.htm" -->
Last modified on
File Size
Relative references are relative to the current directory.
Absolute references are relative to the document root.
Relative reference: File size in bytes <!--#fsize file="menu.htm" -->
File size in bytes

Absolute reference: File size in bytes <!--#fsize virtual="/includes/menu.htm" -->
File size in bytes

Including the output of commands (carefully)

Include the output of a cgi script.
The cgi parameter is relative to the document root of the server.
<!--#exec cgi="/cgi-bin/datetime.pl" -->


Including the output of a Unix command.
The cmd parameter is an absolute file system path.
<!--#exec cmd="/usr/local/bin/traceroute ${fiu}"-->


Using Conditional Statements

It is possible to use an if statment with SSI files. The conditional directives are if, elif, else, endif. It is also possible to do pattern matching using  /pattern/. Here is an example that tests if this file was last modified on a weekday

Test if it was modified on a weekday

<!--#if expr="${LAST_MODIFIED} = /Sat/" -->
    <p>Not modified on a weekday; modified on Saturday 
<!--#elif expr="${LAST_MODIFIED} = /Sun/" --> 
    <p>Not modified on a weekday; modified on Sunday 
<!--#else --> 
    <p>Modified on a weekday 
<!--#endif -->

Not modified on a weekday; modified on Saturday

Not modified on a weekday; modified on Sunday

Modified on a weekday

Change LAST_MODIFIED to a different day

<!--#if expr="${LAST_MODIFIED} = /Sat/" -->
    <!--#set var="LAST_MODIFIED" value="Monday" -->
<!--#elif expr="${LAST_MODIFIED} = /Sun/" -->
    <!--#set var="LAST_MODIFIED" value="Monday" -->
<!--#else -->
    <!--#set var="LAST_MODIFIED" value="Sunday" -->
<!--#endif -->

Test if it was modified on a weekday again

<!--#if expr="${LAST_MODIFIED} = /Sat/" -->
    <p>Not modified on a weekday; modified on Saturday 
<!--#elif expr="${LAST_MODIFIED} = /Sun/" --> 
    <p>Not modified on a weekday; modified on Sunday
<!--#else --> 
    <p>Modified on a weekday 
<!--#endif -->

Not modified on a weekday; modified on Saturday

Not modified on a weekday; modified on Sunday

Modified on a weekday

Displaying all of the environment variables

<!--#printenv -->