To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97
Skill 8 Creating Dynamic Web Pages: More Tools
- Using server-side includes (SSI)
- Generating graphics on the fly
- Making a graphical access counter
Youve done some fairly substantial Perl programming by now if youve completed the exercises in the earlier chapters of the book. You should have a pretty good understanding of how Perl and the Common Gateway Interface work together to create dynamic, interactive Web pages.
In fact, your experience has probably led you to be a little frustrated with the limitations of HTML. Its one thing to design and implement a full-blown CGI program for a relatively complex task such as a Web site guest book or an access counter. But what about something simpler, such as displaying a small document or using the Web servers environment variables? Unadorned HTML cant do it; you would have to write a CGI program.
Similarly, while HTML is quite good at displaying graphical images in the standard JPEG and GIF formats, it has no facility for manipulating them, or even making the simplest decisions.
Server-side includes (SSI) was invented to give some much-needed muscle to HTML. Indeed, as youll learn in this skill, SSI can be a very powerful tool. Youll also learn about Ghostscript, a utility that you can use with Perl to create and manipulate graphics for your Web page.
Using Server-Side Includes
What are server-side includes? Weird as it may seem, the name actually is descriptive: SSI is a function of the Web server, so the processing of a command takes place on that side. One of the most usefuland often usedSSI functions allows you to include the contents of a file in an HTML document.
TIP: C/C++ programmers encountering SSI for the first time will be reminded of their #include directive, which copies the contents of an external file. Perl programmers have a similar capability in the require function.
SSI is a set of directives to the Web server that are embedded in comment tags right in the HTML document. For example, the directive
<!#include file="NewStuff.html">
would copy the contents of NewStuff.html into the Web page, to be displayed by the visitors browser like any other HTML file.
NOTE: Comments in HTML are statements enclosed by <! and > and are ignored by the Web server and the visitors Web browser. They are handy for documenting non-SSI HTML files. Also, if an SSI directive happens to be in a file being processed by a Web server that doesnt do SSI, it too will be regarded as a comment and skipped over.
SSI is built into the Web server, which means that you dont have it if your server doesnt. The lack of SSI capabilities in a server is somewhat more prevalent than it used to be, now that more and more Web sites are being powered by non-UNIX operating systems. SSI is a standard feature of the NCSA and Apache servers; oddly, the CERN server wont handle it. See the sidebar that follows about Faking Out the Cern Server.
In the PC world, the Sambar server supports the full set of SSI directives as of version 4.03 and Netscapes latest Web server understands SSI, too. Microsofts Internet Information Server (IIS) is limited to one SSI command.
However, SSI is so useful that it wont be the exclusive property of UNIX Webmasters for long. Its worth your time and effort to learn the SSI commands, even if you cant use them right away.
Assembling the SSI Directives
The list of SSI commands is not very long. However, you may be surprised at the power they can add to the simplest Web page.
The format of an SSI directive generally looks like this:
<!#DIRECTIVE PARAMETER="ARGUMENT">
Notice that the command is embraced by the HTML comment tags <! and >. Its important that you dont leave these out, because an SSI-enabled Web server will be looking for them to begin interpreting any embedded commands.
|