I’ve discovered SSI

Back in November, I posted about a problem I’ve had with my Mozilla and Netscape help sites. They had become too big to have all FAQs on one page, and were laborious to update. It was obvious that I needed to give each FAQ item its own page, but that presented a different problem. If I ever want to update the schema of the site, I’d have to manually edit hundreds of pages.

Frames, as any good webmaster will tell you, is out of the question. I’ve been spending quite a bit of time learning/experimenting with content management systems, but every one I’ve tried is overkill (Not to mention the ugly URLs, they create).

Finally, unlike Bono, I’ve found what I’m looking for. It’s Server Side Includes (SSI). “As its name implies, its primary use is including the contents of one file in another.” In other words, I can create a file containing the HTML of my site header, and have all pages use that file, for the header. If I make any changes to that file, it is reflected on all pages.

I can’t wait to start using it. I feel like I’ve been walking to work everyday, and have just learnt how to drive a car. My life is about to get much easier. 🙂

5 Responses

  1. Dao March 5, 2006 / 4:58 am

    Maybe you should discover mod_rewrite:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*/$ /index.php

    And PHP:

    <!– header –>
    include $_SERVER[‘REDIRECT_URL’].’/index.html’;
    <!– footer –>

    This way, you don’t have to include your site header on every single page because the content gets included.

  2. Anonymous March 5, 2006 / 5:23 am

    Thats a bad idea:

    include $_SERVER[‘REDIRECT_URL’].’/index.html’;

    A better one:

    $handle = fopen ($_SERVER[‘REDIRECT_URL’].’/index.html’, “r”);
    while (!feof($handle)) {
    $buffer = fgets($handle, 4096);
    echo $buffer;
    fclose ($handle);

    It is more secure to use fopen than to use include which could lead to a massive security hole.

  3. Dao March 5, 2006 / 10:38 am


    I only wanted to put my idea across. Of course, if you don’t work with .php files (as I do) but .html, file_get_contents() is better than include(). But in any case, one should always check if $_SERVER[‘REDIRECT_URL’] is valid.

  4. glob March 5, 2006 / 7:39 pm

    duh 🙂

    you can SSI any page, including .cgi

    use envrionment variables to pass information into the SSI.

    you can nest SSI

    a major problem with using ssi for the header is you end up with every page having the same title.

    a way around this is:

    <!–#set var=”title” value=”whatever” ->
    <!–#include virtual=”header.shtml” –>

    and in header.shtml:

    <title><!–#echo encoding=”none” var=”title” –></title>

  5. James March 6, 2006 / 1:15 am

    If you did not want to depend on a server technology to do a runtime include of the files, you could try using Tagneto (http://tagneto.org — disclaimer, I develop Tagneto).

    It can be used as a templating system that is run offline, once, to generate the output content. Since it does not require server-side technology to generate the output, the output could even be served from local disk (allowing you to offer downloadable zip/gz files of the HTML for offline browsing).

    It supports including files and even conditional includes, as well as overlays. To inject header content with the overlays, you don’t need to specify an include tag but instead in the tagneticconfig file specify that if the Tagneto engine sees a BODY tag in the source, inject the header content after the BODY tag.

    To make Tagneto’s web site, I just use Nvu (http://www.nvu.com) to author plain, vanilla HTML. Then I run that HTML through Tagneto and use overlays to inject the CSS and HTML that creates the style for the site. Right now the style for the site is not very interesting, but I can change it later in the overlays and easily re-style the site.

Comments are closed.