Server Side Includes

Thursday, 11-Sep-2003 10:57:30 CDT


Web documents are usually served by hal-pc.org as plain, ASCII text files with markup, or HTML tags. The end-user's browser translates, or parses, the tags and formats the page. Along with basic formatting tags, web documents can contain commands that the server locates and executes before the document is sent to the end-user. These commands, called server side includes can be used to:

Using Server Side Includes at hal-pc.org

HALNet's runs the Apache web server, configured to parse any documents that end in .html or .shtml for server side includes. Commands to the server always conform to the following format:
<!--#command attribute=value-->
Below are some useful commands that can be included within your documents.

include

The include command inserts a text file into the parsed file. The include command can be used in one of two ways:

<!--#include virtual="/path/to/file/to/be/included.html"-->
or
<!--#include file="relative/path/from/current/directory"-->
Be sure that these files do not contain duplicate <HTML></HTML> <HEAD></HEAD>, or <BODY></BODY> tags.

echo

The echo command prints data from an environment variable. A command that would determine and insert the date at the time (local time zone) that the document is loaded looks like this:

<!--#echo var="DATE_LOCAL"-->
(var stands for variable)

The following line would appear in your page when it was served to the user:

Thursday, 20-Nov-97 13:19:39 EST
Other variables you can use include:

fsize

The fsize command prints the size of a designated file. The attributes accepted for fsize are the same as those used for the include command. For example, the following command would return the size of this file:

<!--#fsize file="ssi.html">
The following line would appear in the page when it was served to the user:
6k

flastmod

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

<!--#flastmod file="ssi.html"-->
to get the following output:
Thursday, 20-Nov-97 16:52:37 EDT

config

To change the format of the output from these commands, use the following:

<!--#config timefmt="value"-->
replacing value with any of the following:
%a    Day of the week, abbreviated
%A    Day of the week, complete
%b    Month name, abbreviated
%B    Month name, complete
%d    Date (1, not 01)
%D    Date as %m/%d/%y  (6/23/97)
%e    Date (01)
%H    24-hour clock hour
%I    12-hour clock hour
%j    Decimal day of the year
%m    Month number
%M    Minutes
%p    am | pm
%r    Time as "%I:%M:%S  AM | PM"  (07:17:39 PM)
%S    Seconds
%T    24-hour time as "H:%M:%S"  (16:15:15)
%U    Week of the year
%w    Day of the week number
%y    Year of the century  (97)
%Y    Year  (1997)
%Z    Time zone  (CST)
exec

For security reasons, hal-pc.org does not allow the exec command to be used in server parsed HTML documents.