next up previous contents
Next: Forms: Facilitating User Input Up: The Other Side of Previous: A Brief Overview of

Server-Side Includes

One of the newest features that has been added to web servers is that of Server-Side Includes or SSI. SSI is a set of functions built into web servers that give HTML developers the ability to insert data into HTML documents using special directives. This means that you can have dynamic documents without needing to create full CGI programs.

The inserted information can take the form of a local file or a file referenced by a URL. You can also include information from a limited set of variables-similar to environmental variables. Finally, you can execute programs that can insert text into the document.

Note The only real difference between CGI programs and SSI programs is that CGI programs must output an HTTP header as their first line of output. See "HTTP Headers" in Chapter 19, "What Is CGI?," for more information.

Most Web servers need the file extension to be changed from html to shtml in order for the server to know that it needs to look for Server-Side directives. The file extension is dependent on server configuration, but shtml is a common choice.

All SSI directives look like HTML comments within a document. This way, the SSI directives will simply be ignored on Web servers that do not support them.

Below is partial list of SSI directives supported by the many servers. Not all Web servers will support all of the directives in the table. You need to check the documentation of your web server to determine what directives it will support.

<!-#config timefmt=mt="%c"->
-- Changes the format used to display dates.
<!-#config sizefmt=mt="%d bytes"->
-- Changes the format used to display file sizes. You may also be able to specify bytes (to display file sizes with commas) or abbrev (to display the file sizes in kilobytes or megabytes).

<!-#config errmsg=sg="##ERROR!##"->
-- Changes the format used to display error messages caused by wayward SSI directives. Error messages are also sent to the server's error log.

<!-#echo var=?->
-- Displays the value of the variable specified by ?. Several of the possible variables are mentioned in this table.

<!-#echo var=ar="DOCUMENT_NAME"->
-- Displays the full path and filename of the current document.

<!-#echo var=ar="DOCUMENT_URI"->
-- Displays the virtual path and filename of the current document.

<!-#echo var=ar="LAST_MODIFIED"->
-- Displays the last time the file was modified. It will use this format for display: 05/31/96 16:45:40.

<!-#echo var=ar="DATE_LOCAL"->
-- Displays the date and time using the local time zone.

<!-#echo var=ar="DATE_GMT"->
-- Displays the date and time using GMT.

<!-#exec cgi=gi="/cgi-bin/ssi.exe"->
-- Executes a specified CGI program. It must be activated to be used. You can also use a cmd= option to execute shell commands.

<!-#flastmod virtual=al="/docs/demo/ssi.txt"->
-- Displays the last modification date of the specified file given a virtual path.

<!-#flastmod file=le="ssi.txt"->
-- Displays the last modification date of the specified file given a relative path.

<!-#fsize virtual=al="/docs/demo/ssi.txt"->
-- Displays the size of the specified file given a virtual path.

<!-#fsize file=le="ssi.txt"->
-- Displays the size of the specified file given a relative path.

<!-#include virtual=al="/docs/demo/ssi.txt"->
-- Displays a file given a virtual path.

<!-#include file=le="ssi.txt"->
-- Displays a file given a relative path. The relative path can't start with the ../ character sequence or the / character to avoid security risks.

SSI provides a fairly rich set of features to the programmer. You might use SSI if you had an existing set of documents to which you wanted to add modification dates. You might also have a file you want to include in a number of your pages-perhaps to act as a header or footer. You could just use the SSI include command on each of those pages, instead of copying the document into each page manually. When available, Server-Side Includes provide a good way to make simple pages more interesting.

Before Server-Side Includes were available, a CGI program was needed in order to automatically generate the last modification date text or to add a generic footer to all pages.

Your particular web server might have additional directives that you can use. Check the documentation that came with it for more information.

Further INFO: If you'd like more information about Server-Side Includes, check out the following Web site: http://www.sigma.net/tdunn/ which has documents detailing some of the more technical aspects of Web sites.

Disadvantage of SSI There is one down side of Server-Side Includes. They are very processor intensive. If you don't have a high-powered computer running your web server and you expect to have a lot of traffic, you might want to limit the number of documents that use Server-Side Includes.


next up previous contents
Next: Forms: Facilitating User Input Up: The Other Side of Previous: A Brief Overview of
dave@cs.cf.ac.uk