Server-Side Includes


Can I have server-side includes?

Yes. The Apache server (and others) support server-side includes, where the server parses the document on the way to the client. Environment variables, the current date and time, and file modification dates are all available.

The file extension that triggers this processing is .shtml, which stands for server-parsed HTML. You can also make the server process .html files this way as well by using the AddHandler directive in a .htaccess file.

For example, to include the current time and date in the data to be sent to the client, use the magic comment string

<!--#echo var="DATE_LOCAL" -->

The nice thing about this is that you don't have to run /bin/date just to put the time and date into your file.

However, the default format for the DATE_LOCAL string is not precisely UNIX time format. To get the precise UNIX format, use

<!--#config timefmt="%a %b %e %H:%M:%S %Z %Y" -->
<!--#echo var="DATE_LOCAL" -->

The timefmt configuration variable is in strftime(3) format, as far as I can tell.

Notes:

  1. This mechanism can also be used to include the last modification date of the file, the name of the document, and the entire environment variable set associated with CGI scripts.
  2. If you want all .html files in a directory to be treated as server-side includes, create a file called .htaccess in the directory. Adding the line AddHandler server-parsed .html will make the server map the standard extension .html into a server-side include instead of plain old HTML.
  3. In order to successfully use server-side includes on CCWF you need to make your login directory ($HOME) world readable and executable with this command:  chmod  o+rx  $HOME.
  4. The exec tag is not available to personal publishers and Web Central publishers in the anonymous FTP area. This is for the same reasons as not allowing CGI scripts.
  5. For more information on server-side includes, see Apache Week, Using Server Side Includes.

    - TeamWeb Answers


  Reviewed 2002 October 30
  Comments to www@www.utexas.edu