|
|
|
Server Side Includes (SSIs)
What is a server-side include?
Most web pages are simple, static HTML pages: a single HTML file that is
sent by the server to a user's browser on request.
Server Side includes (SSIs) provide increased functionality, allowing some elements of your web pages to be dynamically generated by the server. Some of the things you can do with SSIs include:
-
Pasting the
contents of another file into your page
.
On large web sites it is a common practice to keep standard header and footer information (common navigational devices and so on) in separate files that are appended to web pages by the server each time a file is requested. There are several advantages to this: it shortens development and maintenance times for web authors; it provides a standard navigational interface for the user; and it ensures consistent corporate or organisational branding, look and
feel.
-
Displaying the file size, name and modification time
Being able to have the server generate these details, especially the last modified time, is useful. It ensures this information is always available to users, and saves on development time.
-
Showing the current date, time, browser, etc.
This feature is useful when you, or visitors to your site, need to know
what the server knows.
The Apache web server software used at Monash supports these general SSI features, and includes some additional ones:
-
Conditionals
These allow you the flexibility to tell the server to do something based on certain conditions. For example, you can tell the server to
do X
if the user's browser is Netscape, and
do Y
if the browser is Internet Explorer. Or you can tell the server to
include header A
if the page being
requested is page 1 or
include header B
if the page being requested is page 2.
-
Variables
Variables can be set for additional functionality. For instance, you may want to produce a page that shows the modifications dates for each of the files that comprise your web site. You could do this by passing variables (the name of the document you want the last date modified information on) to the command that tells the server to display the last date modified.
SSIs at
Monash
All of the central Web servers (and
yoyo
)
support SSI, with two caveats.
-
None support the (rather insecure)
#exec
feature, which allows you to include the output of a command executed
on the web server. (You should use
#include virtual
to
include the output of a CGI program instead.
This is one of the areas where Apache differs from NCSA)
-
You cannot
#include virtual
from another
server or site.
How to use SSIs
SSI commands are text strings inserted into regular HTML files. All SSI commands take this form:
<!--#element attribute=value attribute=value ... -->
A list of commands and information on how to use them is available in the online documentation provided by
Apache.
SSIs included in HTML files will only work if the server has been instructed to treat
your HTML files as
server-parsed
documents. The simplest way to do this is to rename your files to end in
.shtml
, but you can also give instructions to the server by using a
.htaccess
file. For more information on how to do this, please contact your local webmaster or the
ITS Web Team
.
SSI Information Links
-
NCSA's
SSI tutorial
.
-
Apache Week
has a
feature
article about
server-side includes
with useful examples. This article was written before the XSSI module
was integrated into the regular Apache
mod_include
, so references
to the XSSI module as a separate entity should be ignored.
|