Automatically Adding the Last Modification Date to Your Page
Now that you know what it takes to make SSIs work on your server, you might be asking yourself, “What good are they?” Well, as you’ve surfed around the Web, I’m sure you’ve seen pages that include the last time they were modified, like the one in Figure 3.1.
Figure 3.1 : Including the last modified date on your Web page.
At the bottom of Figure 3.1, the date the file was last modified is printed. If you try to look at the HTML source that produced this file, you will see only normal HTML commands and the date displayed on the Web page. I have deleted most of the HTML that builds this Web page, but the HTML you should be interested in is on line 14 of the snippet shown in Listing 3.2. It sure doesn’t look special, does it? You can’t guarantee that the author just isn’t changing the date manually, but I suspect that an SSI is responsible for the date on line 14.
Listing 3.2. HTML including the last modified date on your Web page.
[prior HTML deleted]01: <hr>02: <P>Wanna <a href="rliwd/suggest.html">suggest</a> a topic? Wanna be03: <a href="notify.html">notified</a> when new lessons are on line, or changes04: are made?</P>05: <hr>06: <P><img src="/pix/paws/blue.gif" alt=" * ">Comments to Brian Exelbierd07:(<a href="tutor.mail.html">email@example.com</a>)08: <BR>09: <img src="/pix/paws/red.gif" alt=" * ">10: To bex's <a href="/~bex/index.html">home page</a>11: on the <a href="/index.html">CATT</a> WWW Server</P>12: <P><A HREF="http://www.halsoft.com/html-val-svc/"> <IMG13: SRC="/pix/valid/valid_html3.0.gif" ALT="HTML 3.0 Checked!"></A>14: Last Updated and Validated on September 17, 199515: </P>16: </body>17: </html>
The HTML that produced the line
Last Updated and Validated on September 17, 1995
did not require the author to change the date every time the HTML file was modified. The SSI directive
<!--#flastmod file="file.shtml" -->
checks the last modified field of the HTML file-file.shtml-and sends it to the client along with the rest of the HTML in file.shtml. So, even though I’m not responsible for the HTML in Figure 3.1, I suspect that line 14 looks something like this:
Last Updated and Validated on <!--#flastmod file="index.html" -->
Notice something very special about SSIs: When your server processes the SSI command, it includes the result of the SSI command in your HTML in place of the command itself.
That example is pretty simple, as are most of the SSI commands. And that is their purpose: to allow simple dynamic additions to your HTML files with very little effort. This example gives you a new perspective on some of the neat things you can do with your Web page without having to expend a lot of programming effort.