MyUNIverse | WebCT | Calendar | A-Z Index | E-Mail | Contact UNI | Directory | Search

Click for UNI web site search Click for online phone and e-mail directory search

UNI

UNI Webtools: Resources for Web Developers

 
 

Server Side Includes

Introduction to Server Side Includes

 

Server Side Includes (SSI) are a collection of executable commands that can be used to add dynamic information to web pages. SSI works by embedding directives into HTML documents. The directives execute code which can display environmental variables, show file attributes, include multiple HTML documents, or run external code like a Perl script.

 

Because there are security concerns with running external code directly from the web server, ITS has produced a standard practice. This document describes how executable server side includes are available only by request and recommends that all CGI applications be placed in a "./cgi" directory. Although the standard practice limits one feature of SSI there still are many useful features, some will be introduced in this document.

 

Displaying Last Modified Date

 

In order to comply with UNI's web policy every page at UNI must have a last modified date. One way to accomplish this is by using a Javascript or a Perl script. Another way is to use a SSI directive like the one demonstrated at the bottom of this page. Here is the SSI directive which creates it.

 

Last Modified: <!--#echo var="LAST_MODIFIED" -->

 

Note: Your HTML document must have the .shtml extension in order for the UNI web server to process the SSI directives. The server only processes .shtml files to save cpu resources. Once you switch to .shtml files bookmarks and links will need to be updated.

 

There are many ways to tailor the date format of your SSI directive. In order to customize the date format you must set the time format variable as follows

 

<!--#config timefmt="%D (day %j) at %r"-->

 

Then use the file last modified command to display the modification date of your file

 

Last Modified: <!--#flastmod virtual="/your_file.shtml -->

 

"LAST_MODIFIED" is a variable available to SSI directives. In addition to other SSI variables the CGI environment variables are also available. All of the environment variables and their values can be displayed with the SSI directive

 

<!--#printenv -->

 

Since server side includes are a compiled part of the web server, which is already running, SSI can be faster than starting an instance of Perl. And since the code executes on the server it guarantees the pages will display even on browsers which have javascript turned off.

 

Using Server Side Includes to Display a HTML Document

 

The most commonly used directive at UNI is the include directive. This allows developers to bring together several HTML pages and display them to end users as a single page. The include directive can be used to create dynamic pages or as a management tool.

At UNI we have a collection of header files which are maintained by the public relations office. This allows developers on UNI servers to easily incorporate a standard look and feel to their webspace. It also saves time when updates are needed. Instead of changing potentially thousands of web pages, the public relations office simply updates a handful of pages and those changes immediately propagate through the entire UNI webspace.

 

Here's how it works:

 

1) A user requests a page called index.shtml. Since the file has the .shtml extension the uni.edu web server knows that it should execute the SSI directives in this document.

2) The web server executes all SSI directives. In this example it opens the appropriate HTML documents.

3) The server dynamically replaces the SSI directives with the full content of the HTML documents from step 2 and displays the result, a single html page, to the user.

 

The SSI directive 'include' can incorporate documents relative to the web server's document root by using the virtual attribute. For example,

 

<!--#include virtual="/ssi/smalcss.html" -->

 

The above statement is asking for the file

"http://www.uni.edu/ssi/smallcss.html"

 

One limitation to using SSI is that the included files must exist on your web server. For example, If your web page lives on the web server in the college of natural science you could not use a SSI directive to include html files from iscssun. In fact any reference to http or another web server will automatically create a SSI error.

 

WRONG: <!--#include virtual="http://ww.uni.edu/ssi/wrong.html" -->

 

An Example of Using the Standard UNI Header Files

 

The files which are maintained by the public relations office are stored in the" /ssi" directory of your web server. If your server does not have this directory or SSI is not working, ask your system administrator to download them and turn on non-exec SSI for your directory. You can, of course, create a series of html files and graphics for your department's use; these are in addition to the standard UNI files found in "/ssi".

 

There are many files which are available for public use. Templates for using these files in your design have already been created.

Here's an example of a simple index.shtml file

 

<HTML><HEAD></HEAD></BODY>
<!--#include virtual="/ssi/smallcss.html" -->
</BODY></HTML>

 

It has all the tags of a standard HTML file, it has been stripped of many tags for simplicity. The only content the file has is the SSI directive to include the file "/ssi/smallcss.html".

 

Smallcss.html does not have any of the standard tags which indicate the start or end of the html file or body. It doesn't need them because they have already been provided by index.shtml.

 

Many first time users of SSI find it confusing that the SSI directives don't show up when they view the source from a web browser. This is because the server extracts the SSI directives and replaces them with actual HTML code.

 

This is important to understand because simply pasting the code from a standard SSI file like "/ssi/smallcss.html" defeats the purpose of using SSI. If you don't use the SSI directives once public relations updates "smallcss.html" your pages will not be automatically updated.


Maintained by University Marketing & Public Relations
Last Modified: 3/25/03