home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeWeb Design in a NutshellSearch this book

Chapter 18. Server Side Includes

In layperson's terms, Server Side Includes (SSI) are special placeholders in an HTML document that the server replaces with actual data just before sending the final document to the browser. By the time the document gets to the browser, it looks just like any other HTML page (even if someone happens to "view source"), as though you typed the data into the HTML source by hand.

When the server looks through the file for placeholders (SSI commands), it is said to parse the file. The server then inserts the requested data, which could be anything from the current date and time to other HTML documents to the results of a CGI script. (The complete list of information available via Server Side Includes is listed later in this chapter.)

18.1. How SSI Is Used

SSI allows you to create the framework for pages that will be dynamically generated by the server. For the web author, this can be a powerful tool for managing site production and increasing efficiency. The following are just a few examples of the ways SSI can be used:

  • Placing elements that you use over and over again. If you have an element that appears on every page of your site, such as a complex navigational header, you can use a single SSI command that just sources it in instead. If you make changes to the header, such as changing a URL or a graphic, you need to make the change only once, and it will be updated automatically on all pages of your site.

  • Placing a constantly changing element on your page with a single line. For example, if you maintain a home page that has a message that changes every day, you can use a Server Side Include command (and a script on the server) to replace the message automatically. You never need to touch the source code for the home page -- you just let the server do the work.

  • Show the date and time the page was last updated, or show the current date and time in the user's time zone.

  • Allow multiple users to submit content for inclusion on a web page without giving them access to the HTML source. For example, staff members could send in weekly updates via email. The server could run a script that turns the email into a text file, which is then inserted into the web page via an SSI command.

  • Serve an appropriate web page based on the browser making the request. You can even serve documents based on the user's domain name. (Note that not all servers can perform conditional functions. This is discussed later in this chapter.)

Obviously, these are just a handful of possibilities, but they demonstrate the sort of tasks well suited for Server Side Includes.

18.1.1. Advantages

Server Side Includes offer the following advantages:

  • It's easy to learn the basic SSI syntax and start implementing simple SSI.

  • Most servers provide support for SSI or can add it quickly (check with your server administrator first).

  • Pages can be dynamically generated, including up-to-the-second information and content served based on information about the users' viewing environment.

  • It isn't browser-dependent like JavaScript, so it works for everyone (as long as it works on your server).

  • The commands don't display in the browser, so your methods are invisible to the user.

  • It's less work for the server than processing CGI programs for the same functions.

18.1.2. Disadvantages

There are few disadvantages:

  • Parsing a file and adding information requires slightly more work for the server than serving a straight HTML document.

  • Enabling Server Side Includes on the server may pose a security risk. Talk to your server administrator to find out the policy for SSI on your server.

  • SSI is not as robust a solution for dynamic page generation as other scripting methods such as ASP or PHP.

18.1.3. Getting the Most Out of SSI

The examples in this chapter illustrate the basic form and function of SSI commands. On their own, Server Side Includes provide some useful, though limited, tools for dynamic page generation. The real power of Server Side Includes comes in the combination of SSI commands with CGI scripts running on the server. The CGI programs do the necessary processing before the information is ready to be placed in the HTML page.

If you focus on front-end web design, you can get started right away using the elements and variables listed in this chapter, but you may need to consult a CGI programmer to design the back-end for more advanced SSI solutions.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.