Tutorial on Server Includes.

This page is a brief tutorial on how to user server includes in your html documents. This information is only valid if your server is using NCSA httpd. Also, your administrator must have enabled includes for you to use them.

Author
Jeff Spirko, jas8@lehigh.edu
Date
Jan 26, 1995
Last Mod
Nov 24, 1996
It may be right or wrong, but that's not my fault. :-)


Table of Contents

  1. Introduction
  2. For Lehigh Users
  3. An Example: Signature Files
  4. The Include Format
  5. Defined Variables
  6. References

Section 1
Introduction to Server Includes.

According to the documentation, "NCSA httpd allows you to include the output of commands or other files in your HTML documents." -NCSA httpd docs. For example, It's really nice to have one signature file automatically included in all of your HTML documents. The documentation, however, contains information most useful to the administartors of the server, not to the users. This document is intended to help users make the most of server side includes.

The way this actually works is the server scans certain files for the occurrence of special commands called directives. They take the form of special elements in the document. For example, an element with the name !--#include tells httpd to search out another document and transmit it in place of this element. In this case, include is the name of the directive.

To quote the manual again, "Having the server parse documents is a double edged sword. It can be costly for heavily loaded servers to perform parsing of files while sending them." -NCSA httpd docs. Because of this overhead, some administrators choose not to allow server includes at all, whole most who do configure the server so it only parses files with the extension .shtml. This is so the overhead of the macro processor is not run on every single file. This means that if you have the ability to do server includes, you probably have to rename your files so they have the .shtml extension for server includes to work.


Section 2
Note for Lehigh Users.

Lehigh University runs NCSA httpd as their WWW server, and they have enabled includes, so Lehigh users can use the include directives. Remember, only files with the .shtml extension are parsed. This has been done for the convenience of the users. Please do not force them to disable the feature by abusing it. I suggest including only files in your own directory and also not including large files. Also, avoid nesting includes too far.


Section 3
An Example: Signature Files.

Here is an example of how to user server includes in your html document. The actual command format is described in the next section. For the purpose of example, I am assuming you want to include a signature in each of your html documents.
  1. Create your signature file. Name it signature.html. It can look something like the following: <!-- Beginning of information included from "include/signature.html" --> <HR> To contact me, send e-mail to <code>jas8@Lehigh.edu</code>. <p> <address>Jeff Spirko</address> <code>jas8@lehigh.edu</code> <!-- End of information included from "include/signature.html" -->

  2. Place the following line in the document in which you want the signature to appear:
    <!--#include file="include/signature.html"-->

  3. Since most servers, including Lehigh's, require it, rename that document so it has the .shtml extension.

  4. Open up the page and see if it works. Rejoice. Drink and be merry.

  5. Repeat steps 2 through 4 for each document you wish to "sign".
For other examples of how to use server includes, see More Examples on Lehigh University's WWW Server.

Section 4
The Include format

This information is derived from the NCSA httpd documentation.

Available directives:


Section 5
Variables defined for Parsed Documents

A number of variables are made available to parsed documents. In addition to the CGI variable set, the following variables are made available:


Section 6
References

The real documentation for NCSA httpd is located at NCSA. You can read their tutorial on include files, if you want, but I might not forgive you. :-)

Good luck!

Comments and constructive criticism of this document are welcome.
I'm not quite ready for English Professors, though. :-)

This page has been accessed times since October 4, 1995 at 10:55 AM.

Lehigh University | Examples, Templates, Scripts, and Icons | Jeff Spirko's Home Page.



You can select my address below to send e-mail automatically. Don't forget to edit it.

Jeff Spirko
spirko@lehigh.NOSPAM.edu or spirko@yahoo.NOSPAM.com

This page is Valid HTML 4.01! and Viewable With Any Browser