|
Date Published: 1999-11-01
by D. Jasmine Merced
TNS Group, Inc.
Previously, we discussed what Server Side Includes (SSI) are. This month,
we're building on that discussion to explain to you some of the many things you can do with SSI. Please
note that SSI is (obviously) a server-side issue -- you'll need to have a web server with SSI enabled to
perform any of the functions mentioned below.
- Global Website Updates
- One of the coolest things about SSI is the ability to make your life easy. Have you ever had the
"New Year's" craze, needing to change all of your copyrights from the current year to the new year? Using
SSI can make this one of the easiest tasks of the year instead of one of the most dreaded.
SSI makes this task easy by allowing you to "include" an external file into your html document.
For example, you have a footer (with that copyright) that you would like to show on every page in
a web site. You have named the footer file footer.txt. In your main html document (let's call it
index.shtml), you would type:
<!--#include file="footer.txt"-->
What this command does is insert the footer.txt file in the exact location where you've placed the SSI
code (commonly called "ssi call") on your web page.
On some servers, you'll need to use include virtual instead of
include file.
- Insert Dynamic Server and User Information
- In addition to being able to include other static files into your html pages, you can include some
information that is relevant to your visitor or the time of day. For example, if you put the following
code onto your web page:
You are calling from <!--#echo var="REMOTE_ADDR"-->
will show your web site visitor their current IP#... here's yours:
You are calling from 38.103.63.61
Many people like to include the current date and time on their web page.
<!--#echo var="DATE_LOCAL"-->
will show "Thursday, 04-Dec-2008 19:47:23 PST".
You can also show the date that your page was last update. Here's the code that's present on this page:
This page was last updated on <!--#flastmod file="whateverfile.html"-->
which yields:
This page was last updated on [an error occurred while processing this directive]
- Run a cgi program
- You can execute a CGI program. This is highly contingent on your host. When you use this, your
script has to be tight and have no security holes. For example, if you have a "Quote of the Moment" script,
which inserts a new quote every time your page is reloaded. Some people make you go to a specific page
to look at your random quotes, but SSI allows you to insert your random quote into your .shtml page.
The command would look like
<!--#exec cgi="cgi-bin/randomquote.cgi"-->
This is also to display counters to your page. In order for your
<!--#exec cgi= command to work, you need to make sure that your script
is working. Make sure that permissions are at least 755 (rwxrw-rw-) or higher (depending on your web host),
and if possible, try to run the program first, before including it into your document.
These are just a few things that you can do with SSI. If you'd like to continue your SSI education,
may we suggest WDVL's SSI
Directives article.
D. Jasmine Merced is a partner in Tintagel
Net Solutions Group, Inc. and the administrator of The Perl Archive. She also serves as a Director of
the World Organization of Webmasters. She
can be reached at admin@perlarchive.com.
|