Basic Server Side Includes

Server Side Includes, known as SSI, are a group of commands within html code that interact with the local server. There are a number of variables generally useless for our sites but below are shown those that I find quite useful.

IMPORTANT NOTE: Server Side Includes are server specific. Check with your web space provider to see if they permit server side includes. Most of RootsWeb server space does permit them, if you are sure you've done it correctly and it isn't working somewhere on RootsWeb, ask them about that area (for example, I am not sure they are in use on FreePages space, if anyone finds out for sure, let me know).

ANOTHER IMPORTANT NOTE: SSI can also be a bit tricky when you are working on your page in that they do not show on your screen when you preview your document or view it locally with your browser (unless you have HTTP software installed and most of us don't). You can only check how it turns out by uploading it to the server,

echo is used for inserting certain variable data into a HTML document.

For example:
<!--#echo var="LAST_MODIFIED" -->

shows the last modifed date of the page. It does this by asking the server for the actual date of the html file. The default date appearance results from this command are:
Saturday, 07-Oct-2006 18:39:21 MDT

The date format can be modified using the config command. I prefer the following config:
<!--#config timefmt="%d %b %Y"-->

Adding font appearance for italics and bold and the words "Last edited on" and using the config and echo commands above results in the following:

Last edited on 07 Oct 2006

There are variables for filesize, local date, GMT date, filename and other odds and ends that, in my opinion, just clutter up the page. One that may be useful though to add your url is:
<!--#echo var="DOCUMENT_URI"-->

You will need to add the beginning of your url as in the example coding on:
http://www.rootsweb.com/~seky/sampleheader.html

include allows the insertion of files into HTML documents

There are two arguments that include can take:
file=
virtual=

The argument file= specifies a path to the file to be included relative to the current file. It will only find files that are in the same directory or below that directory. To include the file testthis.html which is in the same directory as your page, you would use this code:

<!--#include file="testthis.html" -->

If testthis.html was in a directory below the current one named inhere your code would be:

<!--#include file="inhere/testthis.html" -->

If the file you wish to include is in a higher directory or up a level and then down again in other sub-directories, you need to use virtual= as your argument. This specifies the path to your file relative to the server directory or the user's personal server directory. For example, I have web spaces on Rootsweb named ~hft and ~seky. If I want to include a file named things.html that lives in ~hft/stuff in a page file that lives in ~seky/inhere named start.html, the code I would put in start.html would be:

<!--#include virtual="/~hft/stuff/things.html" -->

Using an included file is extremely useful for repetitive information such as a footer on every page giving copyright and webmaster information or for a navigation bar repated across many pages. The advantage is that when you need to make any change in it, you need change only the one included file, not all those page files. Using the last_modified echo lets your users know how recently there were changes on that page.

There are other SSI's and once you get comfortable with these, check out html sites or your html books and experiment. You will notice though, if you are using some of the counter codes or search engine codes in your pages that you already have some SSI in your pages, perhaps an exec SSI for a counter code.

You will not be able to see SSI coding in other people's pages by VIEWING SOURCE or even by SAVING AS from the web as the information from the included file is already inserted in the page when you see it.



© MaMaT