How to use server includes and counters
Using Server-Side directives at www.best.com
Contents:
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:
- 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://.....".
- 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.
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).
- At the UNIX prompt, enter: touch index.count
- At the UNIX prompt, enter: chmod 664 index.count
- 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".
- 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.
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.
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.
To display the contents of test-it.cgi, I used
<pre><!--#exec cmd="sed 's/</\</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.
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 of the different types of server-include directives:
- General features common with NCSA's httpd-1.3
- Features that only work with Matt Dillon's http server at www.best.com
- <!--#counter file="name_of_writeable_file"--> to increment
the number stored in a file, and pretty up the results by adding
commas at the millions and thousands columns, and putting on
the ordinal suffix ("st", "nd", "rd" or "th" as appropriate).
- <!--#counternp file="filename"--> to increment the counter
but not print it. (You can use <!--#include file="filename"-->
to get at the number, which is a simple string of digits.)
- <!--#counterpo file="filename"--> to print the current
value of the counter. (Use <!--#include file="filename"-->
to print the value without the commas or "th".)
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