Server-Side Includes (SSI) are commands that allow you to control aspects of the server from within your web page. SSI is useful to add small pieces of information or files, such as the time or a header or footer, to many web pages when they are rendered. If you ever have to edit these files, you only need to edit the one file and the changes appear throughout your web page.
SSI directives have the following syntax:
<!--#element attribute=value attribute=value ... -->
It is formatted like an HTML comment, so if you don't have SSI correctly enabled, the browser will ignore it, but it will still be visible in the HTML source. If you have SSI correctly configured, the directive will be replaced with its results.
The echo element just spits out the value of a variable. There are a number of standard variables, which include the whole set of environment variables that are available to CGI programs. Also, you can define your own variables with the set element.
If you don't like the format in which the date gets printed, you can use the config element, with a timefmt attribute, to modify that formatting. Note that the format codes here are for a Linux server; codes for a Windows server may be different.
<!--#config timefmt="%A %B %d, %Y" -->
Today is
Friday May 18, 2012
You can show the last modified date of a file using
<!--#flastmod file="ssi.shtml" -->
This document last modified
Wednesday November 05, 2008
This element is also subject to timefmt format configurations.
To me, the most major magic of SSI is the ability to grab other files and insert them into my HTML page. I use this for parts of the pages that are the same across all or most pages, such as the header, footer and navigation area. i can also insert files which I have given others permission to edit. Since these are simple text files with a bit of code, they are easy to edit.
<!--#include virtual="footer.htm" -->
Copyright PC Club of Charlotte - 2008 Article by Dewey Williams
The files included using SSI should not be full HTML files with a DOC TYPE, header, html and body tags sicne they are being inserted into a file that already has those sections. To differentiate from regular HTML file, I place most of my include files in a special folder. i also give them an extension different from my default HTML file extension.
For SSI files to be processed by the server, the server most know which files to look for SSI directives in. The standard is to use .shtml as the extension for SSI-enhanced files.