SSI Execution
Server Side Includes  
 

 


Normally, web documents are sent to the browser of the person who requests them (the client) as regular text files. HTML tags in the document are parsed by the browser of the client to format the page.

In order to include dynamic content in the documents that can change each time the document is served, a web server can be told to parse, or look for and execute, commands that are present in the document before it is sent to the client's browser.

Some of the things that these commands to the server can do are:

  • print the current date and time or the date and time that the file was last modified
  • include the contents of a particular file
  • execute a cgi script

Using Server Side Includes on The Westford Web

The Westford Web server is configured to parse any document that is named with the file extension .shtml.

Commands to the server always conform to the following format:

 <!--#command attribute=value--> 

Below are some useful commands that can be included within .shtml documents.

include

The include command inserts a text file into the parsed file. This can be a CGI script if the CGI script outputs HTML, such as our counter script. It can also just be another HTML document. The permissions on the included file must be set to allow access to the user requesting it.

The include command can be used as follows:
 <!--#include file="relative/path/from/current/directory/filename.inc"--> or, if in the same directory, <!--#include file="filename.inc"-->

echo

The echo command prints data from a specific variable. For example, you can print the date at the time (local time zone) that the document is loaded. The command looks like this:

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

(var stands for variable)

and will return the following output:

Friday, 03-Feb-2012 23:27:31 EST

Other values you can use for the var attribute include:

  • DATE_GMT - same as DATE_LOCAL but in Greenwich Mean Time
  • DOCUMENT_NAME - name of current document
  • LAST_MODIFIED - date that current file was last modified

as well as any variables in the CGI Variables set.

fsize

The fsize command prints the size of a given file. The attributes accepted for fsize are the sam e as those used for the include command. For example, to print the file size of this document, I would use the following command:
 <!--#fsize file="ssi.shtml"--> 

the output would look like this:

7.8K

flastmod

flastmod prints the date that a given file was last modified. The attributes are the same as those f or include and fsize. To see when this document was last modified, you would use a command like thi s:

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

to get the following output:

Tuesday, 04-May-2004 11:06:40 EDT

Return to the Tools index