Server Side Includes

This week our topic is Server Side Includes (also known as SSIs).
Please see the Example Page using various Server Side Includes. This page demonstrates:

Some of the main reasons for using SSIs are:

The way counters work on my server is that inside the HTML code of the page where you want the counter you insert an SSI which launches a script and inserts the results of the script where you put the code in your web page. If it is working properly when you go to that page and view source you won't see the SSI, but will see the results of the script instead. If there is a problem with the syntax of your SSI or if SSIs aren't supported on that server, then it won't execute the script, and instead you'll see that code in the source and an empty spot where the data should have been.

So, there are two parts to the counter script on my server, the script embedded into the web page and a separate file named the same as your web page but with a .count extension instead of .html. This page contains a line with just a number in it, and it the file that maintains the count of how many times your page has been accessed. This count file must be made world writeable which is something you can do with your FTP program (RIGHT click on the file name with your RIGHT MOUSE button in WS_FTP and a list of options will come up)

Please note that on many servers, this count file is buried in the bowels of the server and is not available to the web hosting customers. On these types of servers the count file is automatically started the first time you call the script, and the only way to increase the count of hits is to visit your page over and over again. ).

What the script does when it executes is it goes to that file with the number and increases it by one (that's why on the example below where I've have included both the text only and graphical counters, the count is larger for the second call of the counter because the script ran twice: once for each counter I inserted in the page.

One example of Counters
Notice when you view source you can't see the SSI command at all. Instructions for adding that and the count file to your site are below:

ANNOUNCEMENT: Graphical counters now validate (script has been fixed)

Simple Hit Counters 

Two simple counters (one text and one graphical) are presented below.

Server Side Include for the counters 

Create a file with the same "basename" as your .html file that you plan to put 
the counter on, but with the extension .count, rather than .html. For example, 
for index.html, you would create a file by the name of index.count. Put this 
file in the same directory as index.html. In this file put the beginning count 
in it (i.e. "0"). An easy way to do this step is as follows: 

You can create it locally on your own PC (in notepad, for example) and then 
use a FTP client to upload it to your Virtual Server (in ASCII mode). Either 
way will work. 

In your .html file put something like the following in the BODY section: 

<!--#exec cgi="/cgi-bin/library/counter/c4.pl"-->

or for a graphical counter: 
      
<!--#exec cgi="/cgi-bin/library/counter/c4g.pl"-->



Reload your web page and see if it works. 


Here's some SSI Resources

Also check out:
http://www.hwg.org/ The HTML writer's guild (look at all the HTML related mailing lists with searchable archives that they maintain). Also, check out their site map for an example of the site map called for on the requirements for an A grade for the final project.