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
The Apache Software Foundation
Apache Project
The Jakarta Project
Apache Module Registry
The Apache FAQ
Apache XML Project
ApacheCon
PHP Server Side Scripting
Apache-Perl Integration Project
Apache-Related Projects
The Java Apache Project

  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, Part 2
Jun 19, 2000, 11 :05 UTC (7 Talkback[s]) (12893 reads) (Other stories by Rich Bowen)

By

This is the second of a three-article series on SSI. In the first article, we talked about how to enable SSI on your server and passed on some very basic examples. In this article, there will be more examples, and we'll talk about some somewhat more involved things that you might want to do with SSI. In the final article, we'll talk about the more advanced features of Apache SSI, including conditional statements.

When was This Document Modified?

In the last article, we mentioned that you could use SSI to inform the user when the document was most recently modified. However, the actual method for doing that was left somewhat in question. The following code, placed in your HTML document, will put such a time stamp on your page. Of course, you will have to have SSI correctly enabled, as discussed in the last article.

        <!--#config timefmt="%A %B %d, %Y" -->
        This file last modified <!--#flastmod file="ssi.shtml" -->

Of course, you will need to replace the ssi.shtml with the actual name of the file that you're referring to. This can be inconvenient if you're just looking for a generic piece of code that you can paste into any file, so you probably want to use the LAST_MODIFIED variable instead:

        <!--#config timefmt="%D" -->
        This file last modified <!--#echo var="LAST_MODIFIED" -->

For more details on the timefmt format, go to your favorite search site and look for ctime. The syntax is the same.

Including a Standard Footer

If you are managing any site that is more than a few pages, you may find that making changes to all those pages can be a real pain, particularly if you are trying to maintain some kind of standard look across all those pages.

Using an include file for a header and/or a footer can reduce the burden of these updates. You just have to make one footer file, and then include it into each page with the include SSI command. The include element can determine what file to include with either the file attribute, or the vitrual attribute. The file attribute is a file path, relative to the current directory. That means that it cannot be an absolute file path (starting with /), nor can it contain ../ as part of that path. The virtual attribute is probably more useful, and should specify a URL relative to the document being served. It can start with a /, but must be on the same server as the file being served.

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

I'll frequently combine the last two things, putting a LAST_MODIFIED directive inside a footer file to be included. SSI directives can be contained in the included file, and includes can be nested - that is, the included file can include another file, and so on.

What Else can I Config?

In addition to being able to config the time format, you can also config two other things.

Usually, when something goes wrong with your SSI directive, you get the message

        [an error occurred while processing this directive]

If you want to change that message to something else, you can do so with the errmsg attribute to the config element:

        <!--#config errmsg="[It appears that you don't know how to use SSI]" -->

Hopefully, end users will never see this message, because you will have resolved all the problems with your SSI directives before your site goes live. (Right?)

And you can config the format in which file sizes are returned with the sizefmt attribute. You can specify bytes for a full count in bytes, or abbrev for an abbreviated number in Kb or Mb, as appropriate.

Executing Commands

I expect that I'll have an article some time in the coming months about using SSI with small CGI programs. For now, here's something else that you can do with the exec element. You can actually have SSI execute a command using the shell (/bin/sh, to be precise--or the DOS shell, if you're on Win32). The following, for example will give you a directory listing.

        <pre>
        <!--#exec cmd="ls" -->
        </pre>

or, on Windows

        <pre>
        <!--#exec cmd="dir" -->
        </pre>

You might notice some strange formatting with this directive on Windows, because the output from dir contains the string "<dir>" in it, which confuses browsers.

Note that this feature is exceedingly dangerous, as it will execute whatever code happens to be embedded in the exec tag. If you have any situation where users can edit content on your web pages, such as with a guestbook, for example, make sure that you have this feature disabled. You can allow SSI, but not the exec feature, with the IncludesNOEXEC argument to the Options directive.

What's Next?

In the next column, I'll talk about some of the more advanced features of SSI, in particular, the flow-control feature (conditional statements) and using variables.

Rich Bowen is the Director of Web Application Development at The Creative Group and the author of Apache Server Unleashed.

  Current Newswire:
ComputerWorld: Open source databases bloom

intelligent enterprise: Will open source databases ever have a major role in business-critical applications?

Open source pioneer closes after failing to identify a qualified investor or acquirer

Yahoo: Open-source database company closes

BYTE: Colocating Your Internet Server

SysAdmin: Books: A User's Report: Apache Desktop Reference

DaveNet: Apache

UnixReview: HTTP Benchmarking, Part 3: Tips and Tweaks

InfoWorld: Red Hat offers Compaq-based e-commerce suite

Covalent to Deliver Optimized Apache Solutions on ProLiantTM servers

 Talkback(s) Name  Date
server side include. ...   ssi   
  Jun 19, 2000, 15:49:37
A way that I have found to have a piece of code that I can paste in to any file ...   File Last Modified   
  Jun 19, 2000, 15:59:18
 A way that I have found to have a piece of code that I can paste in to any file ...   Re: File Last Modified   
  Jun 19, 2000, 17:13:55
When you have a server-parsed html file (i.e., one that has an ssi in it), does ...   Does this consume extra CPU cycles?   
  Jun 22, 2000, 07:37:08
 When you have a server-parsed html file (i.e., one that has an ssi in it), does ...   Re: Does this consume extra CPU cycles?   
  Jun 25, 2000, 14:13:14
I don&#39;t understand why if the include file is a relative path why the path c ...   Include File Paths   
  Sep 23, 2000, 05:47:39
 A way that I have found to have a piece of code that I can paste in to any file ...   Re: File Last Modified   
  Feb 1, 2001, 06:17:31
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.2.12, Apache 1.3.9. and PHP 3.14
Copyright INT Media Group, Incorporated All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/