• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Chapter 32. Server-Side Includes

by Jeffrey and Melissa Niles

In this chapter

SSI Specification

Configuring SSI

Using SSI in HTML

Common SSI Commands

Sample SSI Programs

Server Performance Considerations

A Web server normally doesn't look at the files it passes along to browsers. It checks security—that is, it makes sure the caller has the right to read the file—but otherwise it just hands the file over.

A Web page is often more than one document. The most common addition is an inline graphic or two, plus a background graphic. As you learned in Chapter 28, "Programming CGI Scripts," and Chapter 29, "Custom Database Query Scripts," a page can contain information about other resources to display at the same time. When the browser gets back to the first page, it scans the page, determines whether more parts exist, and sends out requests for the remaining parts. This scanning and interpretation process is called parsing , and it normally happens on the client's side of the connection.

Under certain circumstances, though, you can talk the server into parsing the document before it ever gets to the client. Instead of blindly handing over the document, ignorant of the contents, the server can interpret the documents first. When this parsing occurs on the server's side of the connection, the process is called a server-side include (SSI).

Why include? Because the first use of server-side parsing was to allow files to be included along with the one being referenced. Programmers love abbreviations, and SSI was established quickly. Changing the term later on, when other capabilities became popular too, seemed pointless.

If you are the Webmaster for a site, you might be responsible for 50, 100, or 250 pages. Because you're a conscientious Webmaster, you include your email address at the bottom of each page so that people can tell you about any problems. But what happens when your email address changes? Without SSI, you need to edit 50, 100, or 250 pages individually. Hope you're a good typist!

With SSI, however, you can include your email address on each page. Your email address actually resides in one spot—say, a file called webmaster.email.txt somewhere on your server—and each page uses SSI to include the contents of this file. Then, when your email address changes, all you have to do is update webmaster.email.txt with the new information. All 250 pages referencing it will have the new information automatically and instantly.

SSI can do more than include files. You can use special commands to include the current date and time. Other commands let you report the date that a file was last modified, or its size. Yet another command lets you execute a subprogram in the manner of CGI and incorporate its output right into the flow of the text.


The hallmark of SSI, generally, is that the end result is text. If you implement an SSI page hit counter, for instance, it would report the hits using text, not inline graphical images. From your browser's point of view, the document is all text, with nothing odd about it. SSI works without the browser's consent, participation, or knowledge. The magic is that the text is generated on-the-fly by SSI, not hard-coded when you created the HTML file.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint