Server Side Includes (SSI) is a server scripting language used for web. SSI are directives placed in the HTML pages and accessed on the server when the pages are performed. By this dynamical generated content are added to the HTML page, without using any CGI program or other dynamic technologies.

The SSI is used to include one or more files into the webpage on the web. Apache, LiteSpeed, nginx and IIS web servers supports this language. The SSI files are saved with the extensions .shtml and .shtm.

Enabling SSI in the Directory:

SSI is enabled in a directory by creating a.htaaccess file using the fallowing lines,

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
There are two ways to tell Apache to parse any file. One method is said above, and another method is using XBitHack directive.

XBitHack on
The above command tells the Apache to parse the SSI directive.

Simple syntax of SSI

<!--#directive parameter=value parameter=value -->
Directives are placed within the HTML page and if SSI directive is not enabled in the webpage the SSL will not be seen in the webpage. If the SSI is enabled correctly and the directive will be replaced with the result.

SSI is used to include the content of external file. The syntax to include contents of external page in the current page is:

!--#include file="external.htm"-->
<!--#include virtual="/external.htm"-->
In the first command, it is assumed that the file is located in the same directory and in the second command uses the reference to “external.htm” from the root HTML directory.

Date and Time:

The current date and time of the server can be displayed using

<!--#echo var="DATE_LOCAL" -->
Echo command is used to display the value of the variable. There are many standard variables available in CGT programs. Variables can be defined using Set function. The format of the date can be modified using the fallowing syntax

<!--#config timefmt="%A %B %d, %Y" -->
Today is <!--#echo var="DATE_LOCAL" -->
Document Modification:

SSI can be used to inform the user about the recent modification of the document.

<!--#config timefmt="%A %B %d, %Y" -->
This file last modified <!--#flastmod file="ssi.shtml" -->
Ssi.shtml is replaced with the actual file name .Instead of the filename LAST_MODIFIED variable can be used in general.

<!--#config timefmt="%D" -->
This file last modified <!--#echo var="LAST_MODIFIED" -->
Executing function:

Using exec command, a program or script can be executed. All the output of the program or script is displayed on the webpage.

<!--#exec cmd="ls" -->
Setting Variables:

Using SET directive, one can set variables and values to the variables.

<!--#set var="name" value="Rich" -->
<!--#set var="modified" value="$LAST_MODIFIED" -->
Dollar sign should be used to variable that are not literal strings.

<!--#set var="cost" value="\$100" -->
If you are setting value to the variable, before the dollar symbol / has to be used.

Conditional Expressions:

Conditional expressions are used to compare the values of the variables. If, elif, endif and else condtions are used in SSI and the syntax is:

<!--#if expr="test_condition" -->
<!--#elif expr="test_condition" -->
<!--#else -->
<!--#endif -->
A text is displayed on the web page depending on the time of day using fallowing codes,

Good <!--#if expr="%{TIME_HOUR} <12" -->
<!--#else -->
<!--#endif -->
Bhawani Singh
First release
Last update
0.00 star(s) 0 ratings

More resources from Bhawani Singh