Server Side Includes (SSI) Directives

Server Side Include (SSI) directives are written into the HTML files on the sever. The server interprets them and replaces them with dynamic content before delivering the page to the client web browser. Special tags set SSI directives apart from both the page's content and the HTML tags themselves. This allows the server to be able to determine when something should or should not be displayed, and what should be executed as a command.

Not all servers support SSI. Some servers support it, but it must be enabled. See the SSI server configuration page for more information.

SSI directives all use the same pattern (syntax):

<!--#command option="value"-->

Directives, like HTML comments, begin with <!-- and end with -->. It is important to remember that on many servers, there must be NO SPACE between the last character in the SSI directive and the --> end marker.

The pound sign '#' signals that this is not a comment, but an SSI directive. Here is a list of valid commands, their options and some of the possible values for those variables.

COMMAND OPTION EXAMPLE VALUE & FUNCTION
exec <!--#exec cmd="/absolute_path/executable"-->
<!--#exec cgi="/cgi-bin/script.cgi"-->
Designates where and when executables should be called to insert dynamic content into the page before it is served to the client.
cmd path/executable_filename - Runs a system command and returns the result in the web page. This is usually disabled on most commercial website provider's systems as it would allow users to gain control of the web server. Since the web serer is usually shared between customers, having 1 customer in control of the server might be detrimental to business.
cgi path/script_file.cgi - Use this if there is dynamic content you want to insert in your web page from a CGI.
echo <!--#echo var="value_to_be_echoed"-->
Used to echo a value. Frequently used to display one of the various NCSA HTTPd environment variables for use within the displayed page.
var any evironment variable
config <!--#config errmsg="Admin. defined error message"-->
Allows certain server behaviors to be configured. A frequently used function is to set the time format before displaying the last modified date.
errmsg Insert the appropriate error message this page might generate.
sizefmt If the fsize directive is to be used later, use this to control how the file information is displayed.
timefmt This sets the format for the time if it is displayed.
fsize <!--#flastmod cmd="/absolute_path/executable"-->
Display the size of a given file.
file <!--#fsize file="absolute path/file"-->
<!--#fsize virtual="virtual path/file"-->
 virtual path/filename.ext - Displays
flastmod <!--#flastmod cmd="/absolute_path/executable"-->
Displays the date and time the file was last modified. The formate of the date displayed is modified using the <!--#config timefmt=""--> SSI.
file Absolute path to the file to which you would like to display the last modified time.
virtual Virtual path to the file to which you would like to display the last modified time.
include <!--#include file="absolute_path/file"-->
<!--#include virtual="absolute_path/file"-->
The include statement pulls data from another file on the system and includes it in the delivered web page. Typically, this is used for 'including' a standard header, footer or ads in a page.
file This option is used when the file you want to include a file and want to refer to it using the absolute file system reference.
virtual This option allows you to include another file by using a reference to that file that is relative to the page in which this directive appears. You can't use this to call a CGI script. Use the exec cgi  SSI directive instead.

 

Each of these commands has options usable with it, and those options may specify a value. In many cases, the value is an evironment variable.

For example:

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

This command 'echoes' the IP address of the client.


Bookmark this page and SHARE:  

Search

Donations

Free Training