ssi – server side includes


Server Side Includes (SSI)

Server Side Includes allow you to integrate dynamic content into your web pages. SSIs allow you to execute a CGI program from your page or simply include the contents of a text file. All OLI servers allow SSIs. The ‘ SS ‘ stands for Server-Side and the ‘ I ‘ stands for whatever your consultant tells you. ‘Includes’ and ‘interface’ are both popular. (SPML — Server Parsed Markup Language — is also used to refer to the code you write. Really, you can learn the entire small command set SSI provides before you learn the acronyms.) Basically, SSI is a mechanism whereby you can have our server do something to your HTML before sending it to the browser. SSI does some of the same things CGI does. Some differences are that SSI doesn’t handle forms but CGI is much more involved if you just want another file or the output of a program included in your document. Used properly, the SSI can help make your pages more responsive and can even help make maintaining your site an easier task. Put simply, SSI is sort of like using your HTML server as a cut and paste editor. Here is basically what happens when your server handles a request for an SSI document.

1) The server reads the document and parses (looks for special instructions) it for directives. (directions)
2) Then the server follows the instructions that it finds in the document and merges their results into a finished document.
3) After all this is done, the document is sent to the client browser.

Closer Look (examples):
For every page that you intend to use SSI on, you’ll need to rename the page extension from the usual .htm or .html extensions to .shtml. For example, if you intend to use SSI on your main page, you need to rename your index.html to index.shtml.

Now that the renaming issue is put behind, let’s look at what SSI can do and some reasons why you would use it on your pages. Here are some of the most useful tasks you can do with SSI:

1) Display the last modified date of a web page
2) Display the current date and time (in various formats)
3) Include a document inside another
4) Execute a CGI script or command directly from a web page
Now lets explain how to do these tasks.

Displaying the last modified date of a web page:
To display the last modified date of a web page, you need to add the following SSI code to it:

<!--#flastmod file="ssi.shtml" -->

Displaying the current date and time:
To display the current date and time, add the following SSI code to your web page:

<!--#echo var="DATE_LOCAL" -->

The result would be:
Friday, 03-Aug-2001 15:37:10 PDT

CODE USE OF CODE
%a abbreviated weekday name
%A full weekday name
%b abbreviated month name
%B full month name
%c locale’s appropriate date and time
%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
%n insert a new line character
%p string containing AM or PM
%r time as %I:%M:%S %p
%R time as %H:%M
%S second – 00 to 59
%t insert a tab character
%T time as %H:%M:%S
%U week number of year (Sunday is the first day of the week) – 00 to 53
%w day of week – Sunday=0
%W week number of year (Monday is the first day of the week) – 00 to 53
%x Country-specific date format
%X Country-specific time format
%y year within century – 00 to 99
%Y year as CCYY (4 digits)
%Z time zone name

There are many ways to customize the format of the date output.

Including a document inside another:
This is probably one of the must useful features of SSI. It gives you the ability to include one document inside another.

The SSI code for this is:

<!--#include file="test.htm"-->

Put this code anywhere in your webpage, and test.htm will show up in it’s place. Notice that the file does not have to be a “.htm” or “.html” file. The included file could also be a “.txt” file. You might ask what use would this have on your web site. Here’s an example. Let’s say you have some content that is repeated on many pages of your site like your contct information or even a menu bar. If you save that common content as an individual html or text file, and if you use SSI instead to include that content onto those pages, updating your contact information or adding items to your menu will become as easy as changing just that ONE file. Now, if you didn’t use SSI to include that content, you would have to change EVERY single page the content appears on.

Executing a CGI script or command directly from a web page:
SSI also allows you to run a CGI script or command directly from your webpage. This is where SSI becomes very crucial in many cases. This is not a feature you would use by itself, but in conjunction with a CGI script you have installed. In many cases CGI scripts require that they be called directly from a webpage, which only SSI can do. Basically, to get some of the CGI script to work for you you must use SSI. The SSI code to call a CGI script from the webpage is:

<!--#exec cgi="/scripts/test.cgi"-->

Notice that you only use this command when the CGI script requires the use of SSI to function.

Return to Help Guide Home