Your Daily Source for Apache News and Information  
Breaking News Preferences Contribute Triggers Link Us Search About
Apache Today [Your Apache News Source] To internet.com

Apache HTTPD Links
Apache Module Registry
Apache XML Project
The Apache FAQ
The Java Apache Project
The Jakarta Project
The Apache Software Foundation
Apache-Related Projects
Apache-Perl Integration Project
Apache Project
PHP Server Side Scripting
ApacheCon

  internet.com

Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertising Info
Corporate Info
Apache Guide: Introduction to Server Side Includes
Jun 12, 2000, 10 :43 UTC (26 Talkback[s]) (24354 reads) (Other stories by Rich Bowen)

By

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.

What are SSI?

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.

Configuring Your Server to Permit SSI

To permit SSI on your server, you must have the following directive either in your httpd.conf file or in a .htaccess file:

     Options +Includes

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 .shtml, with the following directives:

        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 .shtml extension, so that those directives would be executed.

The other method is to use the XBitHack directive:

        XBitHack on

XBitHack tells Apache to parse files for SSI directives if they have the execute bit set. So, to add SSI directives to an existing page, rather than having to change the file name, you would just need to make the file executable using chmod.

        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 .html files for SSI, so that you don't have to mess with .shtml file names. These folks have perhaps not heard about XBitHack. The thing to keep in mind is that, by doing this, you're requiring that Apache read through every single file that it sends out to clients, even if they don't contain any SSI directives. This can slow things down quite a bit and is not a good idea.

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.

Basic SSI Directives

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.

Today's Date

        <!--#echo var=DATE_LOCAL -->

The echo element just spits out the value of a variable. There are a number of standard variables, which include the whole set of environment variables that are available to CGI programs. Also, you can define your own variables with the set element.

If you don't like the format in which the date gets printed, you can use the config element, with a timefmt attribute, to modify that formatting.

        <!--#config timefmt="%A %B %d, %Y" -->
        Today is <!--#echo var=DATE_LOCAL -->

Modification Date of the File</4>

        This document last modified <!--#flastmod file="index.html" -->

This element is also subject to timefmt format configurations.

Including the Results of a CGI Program

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.

Other Stuff

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.

  Current Newswire:
WDVL: Perl for Web Site Management: Part 3

Retro web application framework V1.1.0 release

Leveraging open standards such as Java, JSP, XML,J2EE, Expresso and Struts.

Netcraft Web Server Survey for November is available

FoxServ 2.0 Released

Ace's Hardware: Building a Better Webserver in the 21st Century

Web Techniques: Customer Number One

Apache-Frontpage RPM project updated

CNet: Open-source approach fades in tough times

NewsForge: VA spin-off releases first product, aims for profit

 Talkback(s) Name  Date
Hi,i am not to close with the matter but i would like to askhow secure are the S ...   Security on SSI   
  Jun 13, 2000, 10:33:51
man what i have todo for running includes with the latest version of apache for ...   windows 95 sucks   
  Jun 13, 2000, 19:45:01
The configuration on Windows will be the same as on Unix for the things specifie ...   Re: windows 95 sucks   
  Jun 25, 2000, 20:05:37
You can embed directives in a web page to do just about anything - as you observ ...   Re: Security on SSI   
  Jun 25, 2000, 20:10:30
I have followed all of the directions to get SSI to work with my server, however ...   Apache 1.3.14 on Win98 SSI Does not work   
  Oct 25, 2000, 00:56:09
I&#39;m running Apache 1.3.12 with Jserv 1.1.2 on a Win 98 box.I can&#39;t get S ...   Re: Apache 1.3.14 on Win98 SSI Does not work   
  Nov 2, 2000, 02:08:34
This page was incredibly helpfull. It gave me the exact information I needed to ...   SSI documentation = awsome   
  Nov 21, 2000, 18:03:27
I have exactly the same experience using Win95. Changed the httpd.conf file as ...   Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Nov 29, 2000, 22:33:37
 Today is I tried to put those script on my shtml page, and it only gave me Tod ...   help   
  Dec 29, 2000, 05:36:00
I failed with 1.3.14 on W2k too! ...   Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Jan 3, 2001, 11:53:10
I can&#39;t get SSI to work on Win &#39;98 any Ideas of how I can get this worki ...   Re: Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Jan 8, 2001, 04:05:48
If somebody found a way to use SSI under Win98 with Apache 1.3.14, it seems you& ...   Re: Re: Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Jan 13, 2001, 17:18:53
I asked how to set that on Usenet and a Rob (a.k.a. Sisysphus) guy gave me the a ...   Apache 1.3.14 on Win98 SSI   
  Jan 14, 2001, 20:04:10
Apache 1.3.14 on W9x and W2k seems that doesn&#39;t work with SSI .... hey apach ...   Re: Re: Re: Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Jan 15, 2001, 13:54:36
Boy - I&#39;ve tried everything (including that) and I&#39;m in agreement with e ...   Re: Apache 1.3.14 on Win98 SSI   
  Jan 17, 2001, 17:52:29
you need to add "includes" or "+includes" to the options for the directory.This ...   Correct Procedure for SSI Includes on win9x/NT/2k   
  Jan 22, 2001, 11:07:40
Hey, ive read the above instructions, as well as all the posts and still have ha ...   Apache 1.3.14 on RHS Based Mklinux SSI no go.   
  Feb 1, 2001, 23:47:30
i have the same problem on my win me server with apache 1.3.17.i followed all th ...   Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Feb 7, 2001, 14:19:43
I stumbled across this page trying to help a coworker get SSI to work on Windows ...   Re: Re: Apache 1.3.14 on Win98 SSI   
  Feb 21, 2001, 16:44:51
I have different servers, which one of them is used to store all the Ads, banner ...   cgi on other server   
  Feb 28, 2001, 18:34:14
I&#39;m not very familiar with Apache and want to use it to run a PHP based serv ...   how can I run php files on Apache?   
  Mar 14, 2001, 21:39:53
I am attemping to implement a simple counter program written in Perl. The count ...   Perl counter with linux   
  Apr 13, 2001, 19:36:38
> I stumbled across this page trying to help a coworker get SSI to work on Windo ...   Re: Re: Re: Apache 1.3.14 on Win98 SSI   
  Apr 17, 2001, 16:22:26
Hi, I would like to monitor my Apache Server (to get information like http tra ...   Apache API   
  Jun 25, 2001, 07:08:30
Did you restart HTTPD? ...   Re: Re: Apache 1.3.14 on Win98 SSI Does not work   
  Jun 26, 2001, 13:36:00
We are currently implementing Apache web server 1.3.6 on Solaris 7 to act as a p ...   Apache proxy to Concord   
  Oct 24, 2001, 13:48:02
Enter your comments below.
Your Name: Your Email Address:


Subject: CC: [will also send this talkback to an E-Mail address]
Comments:

See our talkback-policy for or guidelines on talkback content.

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
Copyright INT Media Group, Incorporated All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/