1. Home
  2. Tutorials
  3. Web page counter
Yolinux.com Tutorial

Web Page Hit Counter

This server application allows one to add a web page counter.

Download and Build:

Download site:

Home page: http://www.muquit.com/muquit/software/Count/Count2.6/Count.html
Download source: http://www.muquit.com/muquit/software/Count/Count2.6/Count2.6/download/src/wwwcount2.6.tar.gz

Installation:

   tar xzf wwwcount2.6.tar.gz
   cd wwwcount2.6
Edit files to define paths: configure, configure.in, Config.tmpl, Count-config
Changed paths:
  • /usr/local/etc/Counter to /opt/Counter
  • /usr/local to /opt
  • /usr/local/apache/cgi-bin to /home/httpd/cgi-bin (Red Hat 5.x, 6.x) or /var/www/cgi-bin (Red Hat 7.1+)
./build --all   -uses database files /opt/Counter/db/Countdb but can not
                 distinguish between www.domain.com and domain.com.
                 Two separate entries in database, same page, two count totals.

./build --without-database  -Requires page to reference a counter file
                             /opt/Counter/data/page-file.dat
                             You must then reference df=page-file.dat in
                             cgi call.
                             This allows www.domain.com and domain.com to refer
                             to the same file and thus the same hit total.

./build --without-database --prefix=/opt/Count --with-cgi-bin-dir=/var/www/cgi-bin 

Note: you must choose one or the other and can not mix database and file methods for one Count.cgi executable.

As root:
./build --install

  • Do you know the user and group id of httpd' child process [y|n]:? y
  • Enter user id of httpd's child process [no default]:? root
  • Enter group id of httpd's child process [no default]:? root

Note: Red Hat 7.1 introduced the user and group apache instead of root for running the web server. Use apache as the answer to the above questions.

Web server has to have permission to execute cgi and write to Counter files:

   cd /home/httpd/cgi-bin/
   chmod ugo+rx Count.cgi

   cd /opt/Counter
   chown nobody.nobody db logs data
   cd /opt/Counter/db
   chown nobody.nobody *

   cd /opt/Counter/data   - If using count files and not the database
   chown nobody.nobody *

      

Directory paths must allow the web server write access to /etc/Count/db, logs ..

Relocate tools: mv ./src/dumpdb and editdb to /opt/bin

Add line to web page: <img src="/cgi-bin/Count.cgi alt="Count">

Edit: /opt/etc/Count/conf/count.cfg

Set count_reload=Yes so page increments on reload.

To add access for page counter, edit file /opt/Counter/conf/count.cfg and set: strict_mode=NoOnce added you can change it back to Yes or leave it as Yes and use editdb tool.List of [authorized] is the list of web server platforms allowed to access counter. This configures the binary db file /opt/Counter/db/Authdb.

Resulting Installation:

/opt/Counter/...
/home/httpd/cgi-bin/Count.cgi

The following are for build --all and not --without-database:
                    count_admin.cgi
                    count_admin_help.cgi - not needed
                    count_admin.txt      - admin created
/opt/bin/dumpdb
         editdb

Tools: (Does not apply to build --without-database)

/opt/bin/dumpdb /opt/Count/db/Countdb
                             /Authdb
and /opt/bin/editdb /opt/Count/db/Countdb or Authdb
editdb -c - show all commands.
allow you to view and edit the database.

http://----/cgi-bin/count_admin.cgi
This perl script must reference its configuration file:
                            /home/httpd/cgi-bin/count_admin.txt
my $guser_textdb="count_admin.txt";

admin|1|VpZcYs4lguTRs|http://www.domain.com/
user1|0|VpKZnhcYs4olg|http://www.domain.com/%7Euser1/

The "1" specifies access to Authdb and  Countdb
     0                      Countdb only.

Use /usr/bin/htpasswd to generate the encrypted field.
prompt>htpasswd -c xxx user1
New password:
Re-type new password:
Adding password for user user1

This will create file xxx with the encrypted data.

Note %7E ="~".

HTML to add counter to page:

Add the following HTML to your web page to display the counter:

<img src="/cgi-bin/Count.cgi?ft=6&frgb=ff0000&comma=T" alt="Count">

Option Description
ft= Frame around counter of given pixel thickness.
dd= Digit directory. Default is A, Options A-D
cahce=F&expires=0 Instructions to browser: do not cache image, expire immediately.
frgb= frame color in hex RGB
comma= (T) true or (F) false for comma every third digit from the right.
tr= Transparent background T/F
trgb= Make background color RGB, transparent. If black is background then make 000000 transparent to have no background.
display= Default is counter. Also clock, date, countdown, image or version
md= Max digits to display. Default=6
Plus many more options.

Red numbers, transparent background:

<img src="/cgi-bin/Count.cgi?chcolor=T&trgb=000000&df=camarotech.com" alt="Count">

Samples of counter

Related Links: