Home Tech Support Web search Spam Filters Web Mail

Server Side Includes

The following documentation is based on the documentation from Apache. I think it's a little clearer.

"Server-Side-Includes" (SSI, for short), allow the WWW developer to put some of the boring work of HTML on the server. They also allow for a page to be dynamically rewritten whenever someone looks at it.

A simple example, that you may have noticed on some of these pages is the 'last modified' line at the bottom. That's done with the following bit of code in the page:

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

or you can do:

last modified on <!--#flastmod file="thisfile.html"--> by bem

You can change the format of the times if you like, even, by using the SSI config command:

<!--#config timefmt="%Y-%B-%d" -->

Your web page can also display the site name and IP number of the person looking at it. You downloaded this page from , which has the IP number 12.108.31.231.

The code to generate the above two is likewise simple:

<!--#echo var="REMOTE_HOST" -->
<!--#echo var="REMOTE_ADDR" -->

If you looked at the "sample" web page and "viewed the source" on it, you may recall that in HTML, comments start with <!-- and end with -->.

As you can see, that's really a generalization, since the above echo command is technically a comment. As far as HTML is concerned, though, it is. If you look at a web page on your home system that has Server Side Includes in it, you'll just see a blank where the codes are: all the work is done on the CMC.net server. You should look at your page after you upload it to make sure you got them right.

Including files

The last modified output is useful, but it's just the beginning of what Server Side Includes can do for you.

Suppose you're working on a series of web pages, and you want each one to have a "navigation bar" at the top. You really don't want to write this code several times and then have to deal with updating it in a whole slew of pages at once.

That's what SSI is for. You can simply put the navigation bar portion of your page in one file, say "nav.bar", and have the web pages that need it "include" it:

<!--#include file="nav.bar">

In the spot where that code is, everything from the file named "nav.bar" will be inserted. In fact, people looking at your web page will be surprised by the consistency of your page, when you're not really doing the work.

Text Counters

You can have the output of a program inserted at a given spot in your page. For example, if you find the graphic version of the counters a bit gaudy for your tastes, but you still want to have counters, you could insert the following in your page:

This page has been visited <!--#echo var="URL_COUNT" -->
times.

This would produce the following output:

This page has been visited 140 times.

Beware, though, some web browsers think they are smarter than you and will cache results, so it will look like the count never changes. You may need to specifically clear your cache to see the "real" count.

Making It All Work

You need to tell Apache that you want it to handle server side includes. There are two ways of doing this. Which you use is up to you: neither is better or faster or anything.

The first method is to name your file with an extension of .shtml instead of the usual .html. This will serve as a sign to the web server that it should parse the document for server side includes. This is probably the easiest method, though you may have problems editing files with the long extension and making sure it's named right when you upload it.

The other method is to play with what the underlying file permissions on the file. If the "owner-execute" bit is set, Apache will parse the file as if it were a .shtml. The "group-execute" bit will, if set, send as part of the header of the document, a last-modified date that matches the modification date of the file. This allows you to flag a document in a way that helps browsers and proxy servers cache data for you, so your readers get faster access.

Note the implications for counters: if you flag a page with the group-execute bit, the web page will be sent with a modification time. The next time a user comes back and requests that page (even if they use the reload button!), the page will have the same modification time. Some browsers will then display the first page instead of the newly downloaded one. If the content on your page changes often, you probably do NOT want to set the group execute flag.

Changing the file permissions can be tricky. Unless you know your ftp client well, it may be best to stick to .shtml as the extension.

Home Tech Support Web search Spam Filters Web Mail

Copyright © 1997-2008 Emerald People's Utility District

24/7 Technical Support:
Eugene/Springfield Area: 541-344-8283
Within Oregon: 877-282-3523
Outside Oregon: 800-731-4871
Or email support@cmc.net