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 Thursday, 17-Jun-2021 14:46:55 EDT
Last modified on <!--#echo var="LAST_MODIFIED"-->
-
DOCUMENT_NAME
-
The document name is ssi.shtml
The document name is <!--#echo var="DOCUMENT_NAME"-->
-
DOCUMENT_URI
-
The document URI is /~downeyt/webdev/ssi.shtml
The document URI is <!--#echo var="DOCUMENT_URI"-->
-
DATE_GMT
-
The GMT date is Tuesday, 01-Apr-2025 17:02:34 GMT
The GMT date is <!--#echo var="DATE_GMT"-->
-
DATE_LOCAL
-
The local date is Tuesday, 01-Apr-2025 13:02:34 EDT
The local date is <!--#echo var="DATE_LOCAL"-->
All Environment Variables are also Available
-
HTTP_USER_AGENT
-
The user agent is Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
The user agent is <!--#echo var="HTTP_USER_AGENT"-->
-
HTTP_HOST
-
The http host is users.cis.fiu.edu
The http host is <!--#echo var="HTTP_HOST"-->
-
SERVER_NAME
-
The server name is users.cis.fiu.edu
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 (none)
Http accept language is <!--#echo
var="HTTP_ACCEPT_LANGUAGE"-->
Including Files
-
Relative references are relative to the current directory. It is not possible to go up the directory tree.
Absolute references start with / and are relative to the document root.
-
Relative references use the file attribute:
<!--#include file="ssi_include.txt" -->
This is a line of text included from a file in this directory.
Absolute references use the virtual attribute:
<!--#include virtual="/~downeyt/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 www.fiu.edu
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="ssi_include.txt" -->
Last modified on Friday, 19-Oct-2018 15:29:15 EDT
Absolute reference: Last modified on <!--#flastmod
virtual="/~downeyt/includes/menu.htm" -->
Last modified on Wednesday, 19-Dec-2018 15:47:33 EST
-
-
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="ssi_include.txt" -->
File size in K 63
Absolute reference: File size in K <!--#fsize
virtual="includes/menu.htm" -->
File size in K 3.3K
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="ssi_include.txt" -->
Last modified on Friday 10/19/18 (day 292) at 03:29:15 PM
Absolute reference: Last modified on <!--#flastmod
virtual="/~downeyt/includes/menu.htm" -->
Last modified on Wednesday 12/19/18 (day 353) at 03:47:33 PM
-
-
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="ssi_include.txt" -->
File size in bytes 63
Absolute reference: File size in bytes <!--#fsize
virtual="/~downeyt/includes/menu.htm" -->
File size in bytes 3,414
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="/~downeyt/cgi-bin/test.cgi" -->
Hello from test.cgi
<!--#exec cmd="/netdepot/J2SE-1.6/bin/java -cp /home/bear-008/users/downeyt/public/server/data/java SayHello" -->
Including the output of a Unix command.
The cmd parameter is an absolute file system path.
<!--#exec cmd="/usr/bin/date"-->
Using Conditional Statements
Since Apache 2.3.12, the syntax for SSI conditional statements has changed. The new syntax is buggy and needs to be updated. This page uses the old Apache 2.2.x syntax with the directive SSILegacyExprParser on
.
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 -->
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 Sunday
Displaying all of the environment variables
<!--#printenv -->
UNIQUE_ID=Z@wcKsC0ZebzrO9FUUj-BQAAAA4
HTTP_ACCEPT=*/*
HTTP_USER_AGENT=Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
HTTP_ACCEPT_ENCODING=gzip, br, zstd, deflate
HTTP_HOST=users.cis.fiu.edu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
SERVER_SIGNATURE=
SERVER_SOFTWARE=Apache
SERVER_NAME=users.cis.fiu.edu
SERVER_ADDR=131.94.130.45
SERVER_PORT=80
REMOTE_ADDR=3.128.206.81
DOCUMENT_ROOT=/var/www/html
REQUEST_SCHEME=http
CONTEXT_PREFIX=/~downeyt
CONTEXT_DOCUMENT_ROOT=/home/bear-d/users/downeyt/public_html
SERVER_ADMIN=root@localhost
SCRIPT_FILENAME=/home/bear-d/users/downeyt/public_html/webdev/ssi.shtml
REMOTE_PORT=60035
GATEWAY_INTERFACE=CGI/1.1
SERVER_PROTOCOL=HTTP/1.1
REQUEST_METHOD=GET
QUERY_STRING=
REQUEST_URI=/~downeyt/webdev/ssi.shtml
SCRIPT_NAME=/~downeyt/webdev/ssi.shtml
DATE_LOCAL=Tuesday 04/01/25 (day 091) at 01:02:34 PM
DATE_GMT=Tuesday 04/01/25 (day 091) at 05:02:34 PM
LAST_MODIFIED=Sunday
DOCUMENT_URI=/~downeyt/webdev/ssi.shtml
DOCUMENT_ARGS=
USER_NAME=downeyt
DOCUMENT_NAME=ssi.shtml
fiu=www.fiu.edu