|Your Daily Source for Apache News and Information|
|Breaking News||Preferences||Contribute||Triggers||Link Us||Search||About|
This is the first of three articles dealing with Server Side Includes, usually called simply SSI. In this article, I'll talk about configuring your server to permit SSI and introduce some basic SSI techniques for adding dynamic content to your existing HTML pages.
In the second article, we'll talk about some of the somewhat more advanced things you can do with SSI, and in the third week, we'll look at the advanced things that can be done with SSI, such as conditional statements in your SSI directives.
SSI (Server Side Includes) are directives that are placed in HTML pages and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program or other dynamic technology.
The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static and how much needs to be recalculated every time the page is served. SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution.
To permit SSI on your server, you must have the following directive either in your
This tells Apache that you want to permit files to be parsed for SSI directives.
Not just any file is parsed for SSI directives. You have to tell Apache which files should be parsed. There are two ways to do this. You can tell Apache to parse any file with a particular file extension, such as
AddType text/html .shtml AddHandler server-parsed .shtml
One disadvantage to this approach is that if you wanted to add SSI directives to an existing page, you would have to change the name of that page, and all links to that page, in order to give it a
The other method is to use the
chmod +x pagename.html
A brief comment about what not to do. You'll occasionally see people recommending that you just tell Apache to parse all
Of course, on Windows, there is no such thing as an execute bit to set, so that limits your options a little if you're running Apache on Windows.
SSI directives have the following syntax:
<!--#element attribute=value attribute=value ... -->
It is formatted like an HTML comment, so if you don't have SSI correctly enabled, the browser will ignore it, but it will still be visible in the HTML source. If you have SSI correctly configured, the directive will be replaced with the results of the directive.
The element can be one of a number of things, and we'll talk some more about most of these in the next installment of this series. For now, here are some examples of what you can do with SSI.
<!--#echo var=DATE_LOCAL -->
If you don't like the format in which the date gets printed, you can use the
<!--#config timefmt="%A %B %d, %Y" --> Today is <!--#echo var=DATE_LOCAL -->
This document last modified <!--#flastmod file="index.html" -->
This element is also subject to
This is one of the more common uses of SSI - to output the results of a CGI program, such as everybody's favorite, a hit counter.
<!--#exec cgi="/cgi-bin/counter.pl" -->
We'll definately come back to this in another article.
And, of course, there are a variety of other things that we can do with SSI. I need to leave something to talk about next week. So, next week, we'll have a lot more examples, and talk about some of the more involved things that you will be able to do with SSI.
Rich Bowen is the Director of Web Application Development at The Creative Group and the author of Apache Server Unleashed.
|About Triggers||Media Kit||Security||Triggers||Login|
All times are recorded in UTC.
Linux is a trademark of Linus Torvalds.
Powered by Linux 2.4, Apache 1.3, and PHP 4