Server Side Includes Demo

 
This document demonstrates how to turn on and use server side includes.

Please note that turning on server side includes slows the responsiveness of the affected documents because the server must parse them.

Example

What is current date and time?



Ingredients

  • The server side include:

    <!--#exec cmd="/home/jdoe/cgi-bin/showdate.sh"-->

    This text fragment should be placed in your HTML document at the point you want its output inserted. Place the command to be executed by /bin/sh (in this case date) between the quotes.

  • The short script /home/jdoe/cgi-bin/showdate.sh:

    #!/bin/sh
    /bin/date
    
  • The .htaccess file.

    This file should be in the directory which contains the documents you want to be able to use server side includes in. The contents of this file tell the server to parse the .html files in this directory.

    If you are uploading this file be sure to transfer it with your FTP client in text mode. This will ensure the end of line characters are translated appropriately. Unix uses LF (linefeeds) to indicated the end of lines, the Mac uses CR (carrige returns), and DOS uses CR LF pairs at the end of lines.

    Note: Server Side Includes operate a bit differently on the new servers (servers running Apache 2.0.46 or >)

    Use the following syntax in your .htaccess file:

    AddOutputFilter Includes html
    Options +Includes

    It is not necessary to provide the mime-type line for html in your .htaccess in this case, as it will have unpredictable and most likely unwanted results.


Security And Performance Issues

There are a number of security issues involving server side includes which go beyond the scope of this document. Properly used, server side includes can provide powerful flexibility with limited performance impact. Hurricane Electric imposes a few requirements and conditions on the use of server side includes:
  • Source Available For Inspection

    If your server side include executes a compiled program (for example, one written in C) you must keep the source on the server.

  • Respect For Server Resources

    Your server side include must not create performance problems on the server. Simple guidelines for what is reasonable is the load imposed by imagemap or cgiemail.


Further Study

This example only demonstrates the "exec cmd" variety of server side include. To find out more read NCSA httpd Server Side Includes.

Hurricane Electric
760 Mission Court
Fremont, CA 94539
Tutorial Index
Copyright © 1994 - 2002 Hurricane Electric.
All Rights Reserved.
Voice 510.580.4100
Fax 510.580.4151
Comments? info@he.net