What are "server side includes" and how do I use them?
NCSA httpd, which is the program that serves Eniac's World-Wide Web pages,
allows users to create documents which provide simple information to clients
on the fly. Such information can include the current date, the file's
last modification date, etc. These features of our httpd are called server
side includes.
Server side includes can be put into a regular WWW document, but a file
containing server side includes needs to have a .shtml
extension, instead of the standard .html one. If the
filename of a document does not end on .shtml, all server side include
directives will be ignored!
You should be aware that documents containing server side includes take
longer to access, since httpd needs to parse the whole document while
looking for server side include directives. Please be selective when creating
.shtml files -- unnecessary use of server side includes might slow down
the server, affecting availability of yours and other users' pages.
Using server side includes
All server side include directives have the following format:
<!--#command argument="value">
Each command takes different arguments. Note that there is no space between
the dashes and the # character. Here's the breakdown of supported
commands and their associated arguments:
- include will insert the text of a WWW document into the parsed
document. Any included file is subject to the usual access control.
The only supported argument to the include command is file,
which specifies a path to an HTML document relevant to the current
directory. Neither "..", not an absulute path can be used.
For example, to include contents of the file
http://www.seas.upenn.edu/cets/answers/ns-httpd/include_example.html
I used the following directive:
<!--#include file="ns-httpd/include_example.html" -->
which resulted in the following getting inserted into this document:
This text comes from the file include_example.html
- echo prints the value of one of the include variables. A
number of variables are made available to parsed documents. Some of
these variables are described in NCSA's
CGI Environment Variables listing. Also, the following variables
are available:
- DOCUMENT_NAME: The current filename.
- DOCUMENT_URI: The virtual path to this document (such
as /~user/doc.shtml).
- QUERY_STRING_UNESCAPED: The unescaped version of any
search query the client sent, with all shell-special characters
escaped with \.
- DATE_LOCAL: The current date, local time zone.
- DATE_GMT: Same as DATE_LOCAL but in Greenwich
mean time.
- LAST_MODIFIED: The last modification date of the current
document.
The only valid argument to the echo command is var,
whose value is the name of the variable you wish to echo. For example,
specifying
This document was last modified on
<!--#echo var="LAST_MODIFIED" -->
Displays:
This document was last modified on Friday, 12-Apr-2002 13:10:08 EDT
fsize prints the size of the specified file. Valid tags are
the same as with the include command.
flastmod prints the last modification date of the specified
file. Valid tags are the same as with the include command.
config controls various aspects of the file parsing. There
are two valid arguments:
- timefmt gives the server a new format to use when providing
dates, such as through the flastmod command. This is a
string compatible with the strftime library call under
most versions of UNIX. (See "man strftime" for details.)
- sizefmt determines the formatting to be used when displaying
the size of a file, such as through the fsize command.
Valid choices are bytes, for a formatted byte count (formatted
as 1,234,567), or abbrev for an abbreviated version displaying
the number of kilobytes or megabytes the file occupies.
Information about server side includes was taken from NCSA's
server side includes tutorial, which also describes some commands
that are not available on Eniac, such as the exec command.
|