Ada's
Introduction to SSI
SSI is a very useful component of CGI, as I discovered while working on my school project. Using SSI, you can dynamically embed content onto your webpage or even across your entire site. It is a very handy feature. Better yet, you don't need to know one line of Perl programming to harness and use SSi on your site! -Overview of SSI SSI, or Server Side Includes is basically a feature of CGI (in conjunction with your server) that allows you to dynamically insert a piece of information (such as the current date, any HTML file etc) onto any webpage, and have the browser display it as if it was hard coded onto that page. Let's say you're interested in displaying the current date and time on the top of your webpage. Simply by adding one simple SSI code onto the page (<!--#echo var="DATE_LOCAL" --> ), this is accomplished. The ugly alternative would be to manually edit your webpage and change the date to the current one each and every day. Starting to let SSI, are we? And that's just the beginning! -What do I need to use SSI on my site? Your web host must support SSI parsing on its' servers in order for you to be able to use SSI on your site. How can you find that out? Simple. Do the SSI test on it! 1) Create a webpage, and put the code <!--#echo
var="DATE_LOCAL" --> inside the <body> section
of the page. If you don't see the date, then most likely your web host does not support SSI. Of course, the SSI test is not fool proof, so you should ask your site administrator if you're unconvienced. IMPORTANT: If you site is on Hypermart, you do NOT need to change your file extensions from .htm (or whatever) to .shtml in order to use SSI. Hypermart has SSI enabled for all pages without regards to their file extensions. -Ok, I know my server supports SSI...now what? Now, you learn what SSI can do, and exactly how to use SSI on your web site. One thing at a time, though. First and foremost, for all pages that you intend to use SSI on, you'll need to rename those pages from the usual .htm or .html extension to .shtml. For example, index.html should now be called index.shtml. On most servers, this is the only way the server will know that it should parse and respond to the SSI commands on that page. Assuming that's understood, lets get to the meat of the matter, then. What can SSI do, and why should I use it? Here are some of the most useful things you can do with SSI:
Ok my furry friend, let see how to do each of these things... -Display the current date and time To display the current date and time, add the following SSI code to your webpage: <!--#echo var="DATE_LOCAL" --> The result is this: Wednesday, 12-Jul-2000 01:01:31 PDT
There are ways to customize the format of this output. Take a look at the right table, and the following examples to see how to do just that. Code: <!--#config
timefmt="%m/%d/%y" --> Code: <!--#config
timefmt="%H:%M:%S" --> Code: Today is
<!--#config timefmt="%A --> Piece of cake, right? -Display the last modified date of a webpage To display the last modified date of a webpage, add the following SSI code to it: <!--#flastmod file="ssi.htm" --> The result is this: Thursday, 09-Dec-1999 02:13:48 PST -Include a document inside another This must be one of the most useful features of SSI- the ability to include one document inside another. The SSI code for this is: <!--#include file="myfile.htm"-->Put that anywhere in your webpage, and myfile.htm shows up in it's place. The file doesn't have to be a ".htm" file. It could also be a ".txt" file (ie: myfile.txt). So how is this useful? Let's say you have a peice of content that is repeated on many pages of your site (a navigational bar, for example). By saving that content as an individual html file, and using SSI instead to include that content onto those pages, updating that content becomes merely changing that ONE file. The changes is instantly reflected on all pages containing the SSI include command. The ugly alternative, again, would be to manually edit the navigational bar for each and every page containing it. On sites with hundreds or even thousands of pages, prepare to camp out in front of your computer! -Execute a CGI script or command directly from the webpage Last but not least, SSI allows you to execute a CGI script or command directly from the webpage. This is where SSI becomes not only handy, but critical, in many cases. It's not a feature you would use by itself, but in conjunction with a CGI script you have installed. You see, many CGI scripts require that it be called directly from the webpage, which only SSI can do. In other words, in order to get some CGI scripts to work, you must use SSI. The SSI code to call a CGI script from the webpage is: <!--#exec cgi="/cgi-bin/myscript.cgi"--> Of course, you'll need to change "myscript.cgi" to the script you're trying to call. Ok, so when do you need to call a CGI script, then? If and when the CGI script you're using asks for it! For example, many hit counter or stats scripts require the use of the above SSI call in order to function. Poll and survey scripts too. Just know that when the scripts says you need SSI in order to use it, it means what I'm talking about here.
-Resources on CGI and beyond -The CGI Resource: Probably the only CGI
site you'll ever need. The largest and most comprehensive CGI directory on the web. |