build-website-header
 

Server Side Includes -SSI

Server Side Includes (SSI) are sometimes classed as server side scripts, but they are really a collection of specially embedded commands.

They are extremely powerful and easy to use. They require no knowledge of scripting languages making them ideal for beginners. They are normally all the scripting that most sites require.

Server Side Include Uses

There are two main uses of SSI

  1. Insert date modified, or today's date into a web page
  2. Insert repetitive text like menus, copyright, headers into a page
 

Does your Server Support Server Side Include (SSI)



File Last Modified Date & Time:

You can automatically insert the date that your page was last updated, instead of physically typing in the date each time you update the page. With SSI you simply insert the following command in to your page:

Page last modified on <!--#echo var="LAST_MODIFIED"-->

This will show something like:
Page last modified on Monday, 06-Nov-2000 15:58:18 GMT



Using SSI to Include other Files


One of the main uses of server side includes is to include
Information from a single file into multiple web pages. This is particularly useful for web pages which need to show the same piece of information i.e. copyright notices or same navigation pages.

 Once set up you then only need to change one file to change that information across all of your pages.

An SSI include command looks like this:

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



The source file can even contain HTML characters if required. Includes can save you time and effort when it comes to updating your web site so it's well worth a look for anybody with more than a few pages on their web site.

Server Side Include Examples


Displaying the Date and Time:

To display the local date and time on a web page include the following in an HTML document (usually .shtml) .

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

This will show something like:
Monday, 06-Nov-2000 15:58:18 GMT

File Extensions for SSI

The file that contains the include command usually has a .shtml file extension. Because many people who use SSI only decide to do so after they have constructed their website and are looking for easier ways of updating it then it also possible to get the web server to treat normal .htm/.html files as SSI files by modifying the .htaccess file( UNIX/Linux servers).

If you do this then all .htm/.html files will be parsed by the server which could slow the server if you have lots of files being served ( very very big sites only). However if you are using the SSI includes to include website navigation/copyright or similar then it will be on every page anyway.

If you only need to have it on a few pages then stay with the default and use the .shtml extension for those files or place those files in a separate directory and put a modified .htaccess file in that directory only.

The source file can have any name with or without a file extension (e.g. 'filename.html', 'filename.txt' or just 'filename').

Note: The source file can itself include SSI directives and if it does then it must have a .shtml extension.


Other Ways of Doing the Same Thing

All of the things that you can do with SSI you can also do by using PHP and I personally prefer PHP over SSI.

Related articles and resources: