WEB HOSTING SUPPORT NETWORK
     
 

SSI (Server Side Includes)

Server Side Includes (SSI) is a simple to use server-side scripting language, whose primary use is including the contents of one file into another one dynamically or executing of CGI scripts.

A couple of important guidelines you need to follow:

1) SSI commands always begin with <!--# and end with --> just like:

<!--#directive parameter="value"-->

There have to be quotes or space in front of -->

2) The web page that adds the SSI instruction to include another page or program MUST end with .shtml or .sht rather than .html or .htm.

Some examples of SSI:

1) If you want to insert a file into another one, you can use the include virtual command. The URL to the page you want to insert must be relative to the current web page rather than a full URL. For example:

<!--#include virtual="file.txt"-->

Тhis command includes the contents of file.txt in your file. file.txt and the SSI file must reside in the same folder - notice how this SSI instruction uses a *relative* URL instead of a FULL URL. This is very important to keep in mind when using SSI. And if your file.txt is in a subfolder named my_ssi, you have to add it following way:

<!--#include virtual="my_ssi/file.txt"-->

2) If you want to execute a CGI script (in this case it is a Perl script) and include its output to your web page, use the following code:

<!--#exec cgi="name_of_your_cgi_script.pl"-->

3) Printing the size of a file named file.html residing in a subdirectory called directory is very easy:

<!--#fsize file="directory/file.html"-->

4) To print the last modification date of a specific file, you can use:

<!--#flastmod file="directory/file.html"-->

5) Useful command for debugging:

<!--#printenv -->

It prints out a listing of all existing variables and their values.

6) Variables:

You can easily define and use variables in your SSI scripts. For example, the following command defines the variable PI and assigns a value of 3,14159265 to it:

<!--#set var="PI" value="3,14159265"-->

Use the following command in case you want to print out the value of PI:

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

In addition to the variables in the standard CGI environment, these are available for the echo command, for if and elif, and to any program invoked by the document.

DATE_GMT - The current date in Greenwich Mean Time
DATE_LOCAL - The current date in the local time zone
DOCUMENT_NAME - The filename (excluding directories) of the document requested by the user
DOCUMENT_URI - The (%-decoded) URL path of the document requested by the user
LAST_MODIFIED - The last modification date of the document requested by the user
QUERY_STRING - The information which follows the ? in the URL which referenced this script. This is the query information.

For example, the command below prints the last modification date of the current file:

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

7) Flow Control Elements

The basic flow control elements are:

<!--#if expr="test_condition"-->
<!--#elif expr="test_condition"-->
<!--#else -->
<!--#endif -->

The endif element ends the if element and is required.