Server-Side Includes

FeatureSyntaxExample
Automatically-updated timestamps <!--#echo var="LAST_MODIFIED" --> Updated Sunday, 23-Jan-00 12:42:58 PST
"Include" files -- boilerplate, maintain just one copy <!--#include file="footer.txt" --> Questions or comments? E-mail the webmaster.
Run local commands in shells or interpreters, capture output in web pages <!--#exec cmd="dir" -->
01/23/00  02:17p     166 haha.html
05/20/98  09:59a   1,673 index.html
     2 File(s)     1,839 bytes
Automated file size measurement <!--#fsize file="twain.gif" --> 115K

Server Configuration

Lab
  • Add the following code to an HTML document on your server:
    <p>
    Your browser is:
    <!--#echo var="HTTP_USER_AGENT"-->***
    <p>
    This document was last updated on:
    <!--#echo var="LAST_MODIFIED"-->***
    <p>
    Files:
    <!--#exec cmd="dir"-->***
    <p>
    Note: replace dir with ls -l on Unix.
  • View the document in your browser. Do not open it in your browser as a local file; have Apache deliver it. That is, be sure that the URL shown in the browser's location field starts with http not with file.
  • Observe that there is no text between the colon and the asterisks.
  • Modify Apache's configuration so that server-parsing is applied to all HTML files.
  • Stop and restart the server, and reload the document in your browser.
  • Observe that the server-side includes are now parsed. The browser type, a timestamp, and a file list are shown.
  • Extra credit: repair the strange indenting of the file listing on NT. Hint: NT's dir command outputs <DIR> for each subdirectory.

Documentation