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:
The ability to have the server dynamically assemble web pages on the fly, by including the contents of environment variables, other files, information about files (date modified, size).
The FLASTMOD SSI which shows the date last modified.
The ECHO SSI along with several different variables that ECHO can print to the screen, such as: REMOTE_ADDRESS (the environment variable with the IP address of the computer looking at the page), HTTP_USER_AGENT (The exact client and OS of the browswer looking at the page), HTTP_REFERER (not documented, at the bottom of the page, shows the URL that the web browser was at just before coming to your page)
This page does not demonstrate use of the INCLUDE command which below.
Some of the main reasons for using SSIs are:
Calling standard header html and footer html files that get included at the top and bottom of every page on your site. The main reason to do this is so that if your logo changes, you don't have to change every page on your site, just the one file that has your header, as that is the file thats called from every page on your site.
The table which follows has been inserted using the command <!--#include virtual="sometable.txt"--> -- the contents of that text file simply get added in to your web page (built on the fly).
A table A table Counter scripts are a type of SSI used to increment the "count" of hits a particular page has had.
SSIs are also used to show the size of a file to be downloaded or the date the file was last modified
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.
http://www.anu.edu.au/CNIP/authors/resources/ssisum.html This is one of the better resources I found on SSIs, produced by Australian National University.
http://www.ora.com/info/cgi/ch05.html This is chapter Five in the Programming CGI O'Reilly Book -- this includes a lot of info I didn't see anywhere else on SSIs.
http://webresource.net/html/procenter/ssi.html Yet another Tutorial on SSIs. I think this one is good, but don't remember.
http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html#Format This is the NCSA Tutorial on SSIs -- one of the first, but not the best in my opinion.