Server Side Includes (SSI)
Server Side Includes is a simple way to program your WWW server to insert other files, current time, file time, file size, etc. into your HTML documents.
This allows you to have a separate file with a header or footer that is used in all your HTML pages, so you can update your page color or E-mail address in all your pages by editing a single file.
SSI documents are ordinary HTML files, where the SSI commands are embedded in HTML comments. When a client (browser) requests a SSI document from the server, the server will parse the document for SSI commands, execute these and send the document to the client, making the entire process transparent to the client.
Before Server Side Includes will work, it must be enabled on the server for the directory you are using.
While ordinary HTML comments looks like:
<!-- This is an ordinary HTML comment -->
commands for the SSI parser looks like this:
<!--#element attribute=value -->
This Apache SSI document example consists of the 3 files ssidemo.shtml, colors.ssi and myname.ssi, where the .ssi files can be common to all your HTML documents.
ssidemo.shtml: <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=iso-8859-1"> <META NAME="Author" CONTENT="Poul Petersen"> <TITLE>SSI demo.</TITLE> </HEAD> <!--#include virtual="colors.ssi" --> <!-- This command inserts the content of the file colors.ssi --> <!-- colors.ssi must be in same directory as this file --> This is a simple document for demonstration of Server Side Includes (SSI). <P> Current document name is : <!--#echo var="DOCUMENT_NAME" --> <!-- This command inserts the name of this file --> <P> Current GMT is : <!--#echo var="DATE_GMT" --> <!-- This command inserts Greenwich Mean Time --> <P> Current local date is : <!--#echo var="DATE_LOCAL" --> <!-- This command inserts local time --> <!--#config timefmt="%d %b %Y" --> <!-- This command sets the format for the time display string --> <P> Current local date is : <!--#echo var="DATE_LOCAL" --> <!-- This command inserts local time --> <P> <!--#include virtual="myname.ssi" --> <!-- This command inserts the content of the file myname.ssi --> <!-- myname.ssi must be in same directory as this file --> <FONT SIZE=-2>Copyright © Poul Petersen 1998. Last update : <!--#echo var="LAST_MODIFIED" --> <!-- This command inserts date when ssidemo.shtml was last modified --> </FONT> </BODY> </HTML>
colors.ssi:
<BODY TEXT="#000000" BGCOLOR="#FFFFCC">
myname.ssi : <HR SIZE=1>Poul Petersen, Lynghoejvej 34, Stilling, 8660 Skanderborg, Denmark. <BR>Tel : (+45) 86571199, Fax : (+45) 86570199, <A HREF="http://www.poulpetersen.dk">http://www.poulpetersen.dk</A>, E-mail : <A HREF="mailto:pp@poulpetersen.dk">pp@poulpetersen.dk</A> <BR> <HR SIZE=1>
When somebody request ssidemo.shtml from the server, they will receive:
<HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=iso-8859-1"> <META NAME="Author" CONTENT="Poul Petersen"> <TITLE>SSI demo.</TITLE> </HEAD> <BODY TEXT="#000000" BGCOLOR="#FFFFCC"> <!-- This command inserts the content of the file colors.ssi --> <!-- colors.ssi must be in same directory as this file --> This is a simple document for demonstration of Server Side Includes (SSI). <P> Current document name is : ssidemo.shtml <!-- This command inserts the name of this file --> <P> Current GMT is : Tuesday, 30-Jun-98 15:07:38 GMT <!-- This command inserts Greenwich Mean Time --> <P> Current local date is : Tuesday, 30-Jun-98 17:07:38 CEST <!-- This command inserts local time --> <!-- This command sets the format for the time display string --> <P> Current local date is : 30 Jun 1998 <!-- This command inserts local time --> <P> <HR SIZE=1>Poul Petersen, Lynghoejvej 34, Stilling, 8660 Skanderborg, Denmark. <BR>Tel : (+45) 86571199, Fax : (+45) 86570199, <A HREF="http://www.poulpetersen.dk">http://www.poulpetersen.dk</A>, E-mail : <A HREF="mailto:pp@poulpetersen.dk">pp@poulpetersen.dk</A> <BR> <HR SIZE=1> <!-- This command inserts the content of the file myname.ssi --> <!-- myname.ssi must be in same directory as this file --> <FONT SIZE=-2>Copyright © Poul Petersen 1998. Last update : 30 Jun 1998 <!-- This command inserts date when ssidemo.shtml was last modified --> </FONT> </BODY> </HTML>
Some notes on Server Side Includes:
You can create dynamic pages that can be viewed in any browser as the resulting files can be ordinary HTML.
You can have all common information like header, colors, name, menus, etc. in separate files that are included in all your pages.
Although you can do quite complex things with SSI, you should keep it simple. If you need a lot of functionality, use php instead - documentaton is available on the Apache http server project web site.
With static pages, you can upload the SSI documents to the server, download the resulting HTML documents and then upload these to the server for public access.
You can not preview SSI documents in a HTML editor; you need to upload them to the server for preview.
The SSI parser can use nested includes if the ssi files (in the example above) are in the server's list of parsed documents. Another way is to give the documents that are included the same filename extension as the parsed documents. Most ISP server administrators only allows for one filename extension to be parsed.
If you want comments in the source code, but not want these comments in the final HTML documents, the comments can be included in variables like (for Apache): <!--#set var="comment" value="This is the comment" -->.
Before using Server Side Includes:
Make sure that Server Side Includes is enabled for the directory you use on the server.
Use the proper filename extensions for SSI documents - check with the server administrator.
Use the proper Server Side Includes syntax; specially the conditional commands differ between servers.
Use documentation for the proper version of the SSI module. You can often obtain the version of Apache by requesting a non-existing page from the server.
For more details on Server Side Includes, see:
| Apache Server | Apache http server project |
| NCSA Server | NCSA Server Side Includes |
| Webquest server | Server Side Includes by Mark West |
| Other | CGI resources : Server Side Includes |
