Server Side Includes.

A Server Side Include is an executable line of text in a page of HTML. It only works on Unix servers, and if your web host allows them. It can be used to include one file of HTML on your server into another e.g :

<!--#include virtual="header.html" -->

Note the space after "header.html" and before the -->. If you leave this out, the Include won't work.

This piece of code would cause header.html to be included in the HTML code of the page where you put it, in that place in the code where you put it. It's most commonly used for header and footer sections of web pages; if you wanted to change the look of your entire website in a flash you could just alter the header and footer files, upload them, and all pages that had the necessary Server Side Includes would be altered accordingly.

Clever Trick: Some pages on your web-site will be altered all the time by cgi-scripts. If you have a message board, for example, you could have a file called 'main.shtml', which has nothing else in it in it, except the following code:

 
<!--#include virtual="header.html" -->
<!--#include virtual="index.html" --> [the main page of the board]
<!--#include virtual="footer.html" -->

Everytime main.shtml is loaded, it will display any alteration to index.html, but would save your having to mess with index.html directly, so its' html code won't get munged by having alien code inserted directly into it.

Pages which are set up to be altered by cgi-scripts, like message boards and FFA links pages, are sensitve to being 'tarted up' in WYSIWYG HTML editors. Using Server Side Includes means you can customise the look of the page to your heart's content in perfect safety.

In the example above the file you want to include has to be in your main HTML directory, or in a sub-directory, like so:

<!--#include virtual="/stuff/header.html" -->.

It can't be on another server.

Also, the pages that have Server Side Includes in them have to be executable; they have to have their permissions changed. This is done by the command chmod 705 index.htm in a telnet session, by adding a command to the .htaccess file in that directory, or by saving your page with the extension .shtml.

When you view the source code of your page on your web-server, the SSI code should have disappeared. If it hasn't, you've made a mistake, or your web-host doesn't allow Server Side Includes.

If you're on a Unix server, you should save new pages with the extension .shtml rather than .htm or .html. It will save a lot of bother later, and doesn't affect the appearance of your code.

Server Side Includes can also be used to execute cgi-scripts automatically when the page is loaded in a browser, if your web host allows this. The code to do this is like so:

<!--// cgi="/cgi-bin/tigertom.cgi" -->

This would be useful if you have a hit counter or other script you wanted to run automatically.

Another use of SSI's is to display Server side information, like the time and date:


<!--#config timefmt="%x" --> or
<!--#config timefmt="%A, %B %d, %Y" -->
and when the page was last updated: <!--#echo var="LAST_MODIFIED" -->
And it was last changed on <!--#flastmod file="index.html" -->
The current local date: <!--#echo var="DATE_LOCAL" -->
The current GMT date: <!--#echo var="DATE_GMT" -->
Document name: <!--#echo var="DOCUMENT_NAME" -->
Document URL: <!--#echo var="DOCUMENT_URI" -->
Referer: <!--#echo var="HTTP_REFERER" -->

As the 'copy' function is disabled in this book, I shall include these SSI's in the raw code text file that accompanies the ebook, so you can copy and paste them.

These are only a selection of the variables you can display and manipulate.

Clever uses of these deceptively simple SSI's are discussed in the full, registered version of The Black Book.

 index page