Server Side Includes tutorial

On this page:


The SSI format

All commands to the server have the following format:

  <!--#command tag1="value1" tag2="value2" -->

Each command takes different arguments, and most accept only one tag at a time.

Commands and associated tags

include

The include command inserts the text of a document into the parsed document. Any included file is subject to the usual access control. This command accepts two tags:

  • Use the virtual tag when the included file is not in the same directory as the web page calling it.
  • Use the file tag when the included file is located in the same directory (or subdirectory) as the web page calling it.

config

The config command controls various aspects of the file parsing.

  • errmsg controls what message is sent back to the client if an error occurs while parsing the document. When an error occurs, it is entered in the server's error log.
  • timefmt gives the server a new format to use when providing date and time. This is a string compatible with the strftime library call under most versions of Unix.
  • sizefmt determines the formatting to be used when displaying the size of a file. Valid choices are bytes (for a byte count, formatted as 1,234,567) or abbrev (for an abbreviated version, displaying the number of kilobytes or megabytes the file occupies).

echo

The echo command prints the value of one of the include variables (defined below). The only valid tag is var, whose value is the name of the variable you wish to echo.

fsize

The fsize command prints the size of the specified file, subject to the formatting preference given by the sizefmt parameter to config. Valid tags are the same as those for the include command.

flastmod

The flastmod command prints the last modification date of the specified file, subject to the formatting preference given by the timefmt parameter to config. Valid tags are the same as those for the include command.

exec

The exec command executes a given shell command or CGI script. It must be activated to be used. This command is not activated on Webserve.

  • cmd will execute the given string using /bin/sh. All of the variables defined below can be used in the command.
  • cgi will execute the given virtual path to a CGI script and include its output. Be aware that the server does not perform error checking to make sure your script did not produce unexpected output (e.g., a GIF). The server will interpret any URL location: header and translate it into an HTML anchor.

SSI environment variables

  • DOCUMENT_NAME: The current filename
  • DOCUMENT_URI: The virtual path to this document (e.g., /docs/tutorials/foo.shtml)
  • DATE_LOCAL: The current date, local time zone
  • DATE_GMT: Same as DATE_LOCAL but in Greenwich Mean Time
  • LAST_MODIFIED: The last modification date of the current document
  • HTTP_USER_AGENT: The visitor's browser software
  • HTTP_REFERER: The page from which the visitor came
  • SERVER_SOFTWARE: The version of the web server
  • SERVER_NAME: Your server name
  • REMOTE_ADDR: The remote IP address of the visitor

The timefmt tag values

Following is a list of possible values for the timefmt tag. All times and dates are printed subject to the currently configured timefmt.

Value Description
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%C Default date and time format
%d Day of month, 01 to 31
%D Date as %m/%d/%y
%e Day of month, 1 to 31
%H Hour, 00 to 23
%I Hour, 01 to 12
%j Day of year, 001 to 366
%m Month of year, 01 to 12
%M Minute, 00 to 59
%p String containing AM or PM
%r Time as %I:%M:%S %p
%R Time as %H:%M
%S Second, 00 to 59
%T Time as %H:%M:%S
%y Year within century, 00 to 99
%Y Year as CCYY (4 digits)
%Z Time zone name

Code examples

#echo var

The examples in this table all use the following syntax:

  <!--#echo var="Variable" -->
Variable Code Result
SERVER_NAME <!--#echo var="SERVER_NAME" --> uits.iu.edu
HTTP_USER_AGENT <!--#echo var="HTTP_USER_AGENT" -->
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
DATE_LOCAL <!--#echo var="DATE_LOCAL" -->
Monday, 12-Sep-2005 14:16:37 EST

Current date and time

The examples in this table show different ways of displaying the current date and time.

Code Result
<!--#config timefmt="%A, %d %B %Y"--> Current Date: <!--#echo var="DATE_LOCAL" -->
Current Date: Monday, 12 September 2005
<!--#config timefmt="%a, %d %b %Y, %H:%M:%S"--> Current Time: <!--#echo var="DATE_LOCAL" -->
Current Time: Mon, 12 Sep 2005, 14:16:37
<!--#config timefmt="%D, %r"--> Current Time: <!--#echo var="DATE_LOCAL" -->
Current Time: 09/12/05, 02:16:37 PM

Last modified date

Code Result
<!--#config timefmt="%A, %d %B %Y"--> Last Modified: <!--#echo var="LAST_MODIFIED"--<
Last Modified: Thursday, 07 October 2004

This is document bfsf in the Knowledge Base.
Last modified on 2017-08-17 14:01:13.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.