Working with Server Side Includes
Server-Side Includes (SSI) programs are used by an HTTP server to dynamically generate data for a Web page. An SSI program is executed before the HTTP server sends the HTML document to the HTTP client. You should use an SSI program when you have to process data before it is sent to the HTTP client. In contrast, CGI scripts are executed after the HTTP server sends the HTML document to the HTTP client. For information about CGI script, see "Working with CGI Script." An SSI program can be written in the same languages as CGI scripts. You can use SSI programs to add features, such as a hit counter, to your Web page. A hit counter keeps track of how many HTTP clients access a Web site.
To use SSI programs, you must configure the HTTP server to support parsing. Parsing lets an HTTP server search an HTML document for SSI directives. SSI directives are HTML tags that are included in the HTML code. To configure the HTTP server to accept parsing, you must make sure that the XBitHack directive, located in the srm.conf file, is set to on. For information about the XBitHack directive, see "Using the srm configuration file." You must also ensure that the Options directive, located in the access.conf file, supports the Includes value. This value informs the HTTP server to accept SSI directives. For information about the Options directive, see the "Using the access configuration file."
After you have configured all the necessary configuration files, you must add SSI directives to the HTML code. The syntax for an SSI directive is:
<!--#command argument = "value"-->
The following three commands specify different SSI directives:
includelets you specify a path to an HTML document and inserts its contents. For example, if you want to include a path to the index.html file located in the Islands directory, you must use the following syntax: <!--#include file="/islands/index.html"-->. For example, you can include a file that is repeated in many different Web pages. The advantage to including a file is you only have to amend the file once.
echolets you specify an environment variable, and displays its value. For example, you can display the date that a Web page was last modified using the LAST_MODIFIED variable. To do this, you must use the following syntax: <!--#echo var = "LAST_MODIFIED"-->.
execlets you specify the type of command to execute: cgi or cmd. The cgi option specifies a path to a cgi file that you want to execute. For example, <!--#exec cgi="/cgi-bin/counter.cgi"--> informs the HTTP server to execute the counter.cgi file. The cmd argument informs the HTTP server to execute a system command such as cd (change the directory).
You can create a hit counter using the Perl language and insert it in HTML code as an SSI directive. You must save the Perl program with a .cgi file extension. You can call the .cgi file by using the exec command. For example, you can call the counter.cgi file by adding the following SSI directive into your HTML code:
<!--#exec cgi="/cgi-bin/counter.cgi"-->
This line of code is executed before the HTTP server sends the HTML document to the HTTP client, and the result is displayed to the user.