You are in: School Web Sites » Support in Hertfordshire » Using Server-Side Includes

Using Server-Side Includes

What are they?

Server-Side Includes (SSIs) are instructions that can be placed in a web page to achieve a number of functions. These might include:

  • inserting the contents of another file on the web server into a page
  • writing out the current date and/or time
    Example: the current time is:
  • writing out the date and/or time that the current document (or another document such as a downloadable file) was last modified
  • writing out the size (in bytes, kilobytes or megabytes) of the current document (or another document such as a downloadable file)
  • writing out the name of the current document

Where can I learn about them?

There are a number of useful web sites to find out about Server-Side Includes. Bear in mind while reading these articles that the SSI command exec-cgi is not enabled on HGfL servers.

How do I implement SSIs on my school web site?

For server-side includes to work on a page the page's extension should be .shtml rather than the standard .html or .htm.

If the file extension is not .shtml then you can try as hard as you like, but server-side includes will not work! The .shtml extension tells the server to process any server-side includes held in the page.

As this page has an filename of ssi.shtml this means that server side includes will 'work' on it. Here are some examples:

  • Print out the name of the page: ssi.shtml
  • Print out the current time and date (the time that the page was served from the web server):Wednesday, 03-Dec-2008 23:28:59 GMT
  • Print out the time that the document was modified: Wednesday, 01-Aug-2007 11:07:13 BST
  • Print out the name of the web server this page is on: www.thegrid.org.uk
  • Include another file into the page (in this case include.txt). Note that this file can include HTML commands:
    Here is something in a different file.
    Click on the link in the paragraph above to see what this looks like when it's not included into a web page.
    Note that because the web page contains stylesheet information, these are applied to any tags in the included file...
  • Print out the time that another document was modified - in this case include.txt : Friday, 07-Nov-2003 14:59:30 GMT

How could I use Server-Side Includes on my school web site?

You could:

  • Automatically include re-usable sections of your web page, such as a title bar, navigation table or footer
  • This would go some way to building your pages in a 'modular' fashion. For example, this page is built from a number of server-side includes:
  • Automatically write out the date that pages were last updated, to give users and idea of how current the information on the pages is
  • Write out the date that downloadable files (such as Newsletters or a Prospectus in Adobe Acrobat PDF format) were updated