www.fachtnaroe.ie



Web This site

Server Side Includes

Server side includes is an HTML pre-serving tool that can be used to simplify the creation of your website.

Pages served from the web server are first scanned to see if SSI directives are present. If there are, then the directives are processed by the server and the results are inserted into the HTML being served at the point where the directive is found.

SSI may not be supported by all hosting service providers; also, when SSI is supported only a subset of the directives might be offered. If you can't get your desired directive to operate, first check that some other simpler directives will operate; if so SSI is enabled so check for errors. If SSI is enabled but you cannot get your desired option to go, seek a workaround.

One of the most useful directives is the #include directive. This can be used to insert HTML from one file into another. This is most useful for putting a common header and footer on each page being served from a site.

This site is an example of a site using SSI. The top and bottom of each page is common. This is intended to give every page a common look and layout. Where SSI shines is in labour-saving automatic insertion of HTML and ease of maintenance of a site. When a file is #included using a directive, every page that references that file will change automatically when next loaded in a browser.

The directives need to be inserted in HTML comments. A HTML comment begins with <!-- and ends with --> and is ignored by the browser. Within those comments directives can be inserted.

Failure of an SSI directive will yield an error such as
[an error occurred while processing this directive]
or
Cannot perform flastmod(): Win32 Error Code = XXX
or something similar.

Example: To include a "last modified" timestamp on pages in your site, put an entry like this in your HTML:

This document last modified <!--#flastmod file="index.shtml" -->

...where "index.shtml" is the name of your file and the file is in the current directory.

Notice that a file extension of .shtml is used for the files. This is used to indicate which files being served should be scanned for SSI directives. It is possible to turn on scanning of all files, or to scan files that have the excute bit set (using chmod +x) but .shtml is the only file extension permitted on the server you are using.

Example: To include time on the server, put a line like this in your HTML:

<!--#config timefmt="%A %B %d, %Y" -->Today is <!--#echo var="DATE_LOCAL" -->

The #config gives the format in which the following data should be presented. Codes for formatting are given here:

CodeFunctionExamples
%AFull weekday nameMonday, Wednesday
%aAbbreviated weekday nameMon, Wed
%BFull month nameJanuary, December
%bAbbreviated month nameJan, Dec
%dNumber of day in month03
%eNumber of day in month3, 15
%HHour (1-24)05, 22
%IHour (under 12)03, 11
%jDay number in year12, 245
%mNumber of month1, 12
%MMinute12, 59
%pAM or PMAM, PM
%nNew Line
%SSecond 12, 57
%tTab
%y2 Digit Year99, 03
%Y4 Digit Year1999, 2003
%ZTime ZoneEST, GMT

Example: To include the contents of another file into the file being served use a line like this:

<!--#include virtual="/head.shtml" -->

...where "/head.shtml" is the file to be included and the file is in the root of the directory structure being served. In your case, this file would be in your public_html directory.

Example: To include the output from a script into the HTML of your file use a line like this:

<!--#exec cgi="/cgi-bin/somescript.pl" -->

...where the script is called "somescript.pl" and is in the "/var/www/cgi-bin/" directory.

The are more examples provided by Apache (your http server software) here.

Last updated: 20120111-16:48
back to top
Fachtna Roe, Senior College, Central Technical Institute, Clonmel, Ireland.