How to use server includes and counters

Using Server-Side directives at www.best.com

Contents:

The server must be told to look for directives

Rename your file from whatever.html to whatever.shtml so that the httpd server knows that it is supposed to look for server-side includes and directives. If you cannot rename your file (because there are pointers to it in other peoples hot lists), you have two choices:
  1. Go ahead and rename it and create a short file with the old name that says "This document has moved; its new URL is http://.....".
  2. Put an entry in your .bhtaccess file. (The server here at www.best.com uses .bhtaccess instead of .htaccess like NCSA's server.)
The command required to do the latter are:
    cd ~/public_html
    echo "AddType text/x-server-parsed-html whatever.html" >>.bhtaccess
    echo "AddType text/x-server-parsed-html another1.html" >>.bhtaccess
Then put this line in your document temporarily:
Server software is: <!--#echo var="SERVER_SOFTWARE"-->

You should see "Server software is Apache/1.3.42 (Unix) mod_auth_tkt/2.1.0 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.8r"

This will verify that the server is recognizing your document properly.

To guard against headaches, verify that "echo var" works before attempting counters or CGI stuff.

Using Best's counter mechanism

First decide on a name for the file to hold the count. For instance, daily.count, monthly.count, all.count (for cumulative counters) index.count (for index.html) or test-it.count (for test-it.shtml).
  1. At the UNIX prompt, enter: touch index.count
  2. At the UNIX prompt, enter: chmod 664 index.count
  3. Then enter: ls -l index.count
    It should respond with:
    -rw-rw-r-- 1 yourname mosaic 0 Jun 25 23:01 index.count
    If it says "vip" instead of "mosaic", then you will need to send mail to support@best.com asking them to change your directory to group "mosaic".
  4. Put <!--#counter file="index.count"--> in your document.
This line:
'This is the <b><!--#counter file="test-it.count"--></b> access to this page.'
Results in:
'This is the [an error occurred while processing this directive] access to this page.'

You can also put <font size=+1> in front and </font> behind, but that only works with Netscape's browser, whereas <b> and </b> should display as bold text in all browsers.

If you don't like the ordinal suffixes ("1st", "2nd", etc), you can use:

	<!--#counternp file="index.count"-->
	This page has <b><!--#include file="index.count"--></b> hits.
This will update the counter file with the "np" (no print) option, then the updated count will be included in your document.

Server-side includes - #include file="..."

The previous paragraph shows an example of using <!--#include file="index.count"--> to include the contents of another file verbatim into the current document.

You can use <!--#counterpo file="index.count"--> for Print Only; the file is read, commas and suffix added, but the count is not incremented.

Server-side includes - #exec cgi="..."

Here is an example of putting <!--#exec cgi="test-it.cgi"--> in a ".shtml" document.

[an error occurred while processing this directive]

The contents of my test-it.cgi are:

 Note that the
the script outputs "Content-type: text/html" and a blank line.  They are
required for conformance to the Common Gateway Interface (CGI) standard.

Server-side includes - #exec cmd="..."

To display the contents of test-it.cgi, I used
<pre><!--#exec cmd="sed 's/</\&lt;/g' test-it.cgi"--></pre>
which executed a UNIX command via the Bourne shell (/bin/sh). In this example, sed is a UNIX command that was told to read a file (test-it.cgi), search for the "less than" sign, and replace that character with "ampersand", "l", "t" and "semicolon" before giving the data to the http server.

Note that I used <pre>...</pre> so that the output of the command would not get jumbled up all on one line.

Using counters at sites other than www.best.com

The #counter, #counternp and #counterpo directives work only with Matt Dillon's BESTWWWD server. To install a counter on pages at other sites, you will have to use "#exec cmd=...".

Summary

Summary of the different types of server-include directives:

The real source

If you use the "View Source" function on your browser, you will not see any of these <!--...--> directives; the server has replaced them with the appropriate text.

Click here to look at test-it.shtml as plain text.


Back to Joe Smith at js-cgi@inwap.com