Web Hosting Knowledge Base | Affordable Web Hosting Plans

Server Side Includes (SSI)

You should have seen server side includes (SSI) at work while you are surfing on the web. The visitor counters - "You are visitor no. 30000" or "rotating advertisement banners" are just some examples of SSI. Server side includes can make your webpages more interactive and more interesting. Although SSI is not part of CGI, it can order the CGI scripts to be executed as required.

Basic Concept of Server Side Includes (SSI)

Imagine a visitor (client) type in your webpage address in his/her browser and submit the request. When your web server (server where your website is stored) receive the request, it will become very busy - get the requested page, pack up the page, and send the page to the client. For some web servers, the job is that simple. However, most servers (like our server) will handle more jobs before the requested page is sent to the clients. One of the jobs is to search through the requested page for special commands it recognises. When a command is found, it will be executed according to the nature of the command. This way, we called that the servers are able to do server side includes.

Server Set Up

As you may ask: "If all requested pages are checked before sending to our clients, this will take a lot of computer resources for the server!" The answer is simple: "Since most of the pages will not contain special commands, we can set up our server in the way that only specified documents will be checked for commands before sending to your clients."

Files Extension

Oh! yes, but which documents you have set for your server to be able to use SSI? If you want to use the function of server side includes, you should create pages with the following extension :

  • .shtm,  or
  • .shtml

How to Use Server Side Includes (SSI)

I already know the concept of SSI, but how to use it? SSI are just short commands embedded in your webpages (remember to save your webpages with .shtm or shtml extension when you want to use SSI). When the server find a command in your webpages, the command will be executed and the result will be displayed.

Server Side Includes (SSI) Format

The format of SSI command is very simple :

<!--#command tag1="value1" tag2="value2" ....... -->

To explain a little bit further how it works :

  1. When the server find the <!--#, the server knows that this is a command.
  2. The server will then look for the command to see what command it is.
  3. The following portion tag1="value1" tells the server which program to be executed.

Server Side Includes (SSI) Commands

Below are some of the most common commands of SSI:

#include

This command can be used to insert another document into the current document. Below is an example :

<HTML>
<Body>
..........
..........
Here's the latest information of our site :
<!--#include file ="info.html"-->
..........
..........
</Body>
</HTML>

In the above example, the content of info.html will be inserted after "Here's the latest information of our site :".

Note :Path of file (e.g. info.html) must be relative to the current document.

#exec

This command can be used to execute a CGI scripts. Below is an example :

<HTML>
<Body>
..........
..........
You are visitor no : <!--#exec cgi ="/cgi-bin/counter.pl"-->
..........
..........
</Body>
</HTML>

The cgi script (counter.pl) of the above example will be executed and the number of visitor will be extracted from a file and displaced after the "You are visitor no :"

Note : The cgi scripts (counter.pl) is saved in cgi-bin directory.

web hosting knowledge base