Web Hit Counter is a system for recording and displaying simple web page hits on an Apache web server.

There are three applications/executables. One advances the counts for individual web pages. A second advances the counts for the entire site. You may use one or the other or both. Examples of counts are in the footer of each page on this site. A third executable generates a report on all counters that displays in your web browser.

Status: this software has full stable release status. It has run on this site for a year or so. Warning: I do not yet consider these trials long enough to allow Web Hit Counter to be depended on in mission-critical, high-traffic web pages. Such pages require warranted, commercially guaranteed counters. Web Hit Counter of course carries no warranty of any kind including expressed or implied warranties and you use it entirely at your own risk.

Copyright: Swerdna's Open Source Software: GNU General Public License (GPL).

About Web Hit Counter:

  • Designed to be utterly simple to install and use.
  • The display is text on your web page, styled by ordinary HTML/CSS styling.
  • Comprised of three simple executable files.
  • Every page can have a separate counter and there is an overall site counter.
  • All pages and their counts are listed on a web page that updates each time it is viewed.
  • To install: place the executables on your Apache server and enable Server Side Includes.
  • File locking protects agains data corruption during frequent page hits.
  • A backup set of data is maintained without any action from you.
  • No knowledge of programming or scripting needed.
  • Suitable for .html and .htm pages, not for .php pages.
  • Data are stored in simple text files. No Complex databases.
  • Doesn't depend on a scripting language like Perl or PHP.
  • Open Source software with no other ties, links or constraints.

Download the files: The files are downloadable from this link: Swerdna: WebHitCounter_1.2.tar.gz. Unpack them anywhere. E.g in Konqueror use R-click --> Extract here - and the files will unpack to a containing folder housing five items; viz: three executables, an information page called "information.html" and the web page that displays a list of web pages and their counts in descending order (called "admin.html"). Alternatively use this shell command: tar -xf WebHitCounter_1.1.tar.gz

Placing the executable files: Create a directory/folder called "counter" in the document root of your Apache server. If you want to use a different name, you can, but you'd need to be advanced enough to change the various paths entwined in the "include virtual" statements in your web pages; better to stick with "counter". Place the executable files "increment", "site" and "panel" in the directory "counter".

Tip: Don't move the executables over a Windows or Samba network in the unpacked state. Binary executables are like a good wine - they don't travel well over Samba. Transport them in the original zipped form. You can FTP them to your website in unpacked state (as binary, not ascii).

The directory "counter" houses the counter data as auto-generated text files. There will be one text file for each page being counted and one for the site as a whole. These files contain only a single integer so they are VERY small typically 4 Bytes.

Installing the admin/summary page, admin.html: Put this also in the directory "counter". This page contains code for Server Side Includes and you need to make it executable see the segment below entitled "Enabling Server Side Includes".

Backup data files: Create a directory called "backups" in the directory you created earlier called "counter". The programmes will take care of the backup files. Creating this directory is mandatory.

Permissions: Some Apache servers are configured so the files in and under the document root are automatically writeable for the username that Apache is running. But some aren't. The data files containing page counts are created in directory "counter", one for each web page, and they are created automatically the first time that page is served to a viewer's browser. Another suite of files is created automatically in the directory "backups". If those two processes happen automatically then the permissions are fine. If they don't then you must change the default permissions on directories "counter" and "backups" from drwxr-xr-x to drwxrwxrwx. You can do that with R-click in Konqueror/Nautilus and select Properties --> Permissions. Or you can execute these commands in the document root: chmod 777 counter and chmod 777 counter/backups.

Placing code in web pages: You can place either or both of the following lines of code into your web page/s. The first line calls "increment" and increments the counter for that page alone. The second line called "site" and increments the counter for the whole site. Note that if you want total site counts you must place the code for the site counter (second line just below) in every html/htm page.

<!--#exec cgi="/counter/increment" -->
<!--#exec cgi="/counter/site" -->

Display counts on web pages: You can display either or both of page-counts and total-counts counts for the site on your web page. Simply place one or both of the following lines into the HTML code for the page.

This code will cause the total number of hits for the site to be displayed where the code is placed:

<!--#include virtual="/counter/site.html.counter" -->

and this code will cause the number of hits for the page to be displayed where the code is placed:

<!--#include virtual="/counter/appcounter.html.counter" -->

Note that the only thing that changes in these codes from page to page is the part "appcounter.html" which is the name of the page that you are viewing right now. You change that to your name for the page where you place the code. The rest stays the same.

Styling the display (of counts) The codes above put simple integers on the web page as text with the default styles for the location where they are displayed/called. Look down in the footer at the base of this page, at the twin set of numbers, The small one is page hits and the large one is site hits. The style (colour) is made by wrapping css style around the code as follows:

<span style="color: #FFAA00">[here I put the two pieces of code for the counters]</span>

Any in-page css styling wrapped around an "include virtual" call should work. The world is your oyster.

Enabling Server Side Includes: You enable Server Side Includes for all pages that display counts and for the document root of your web server as well as for the special page "admin.html". To enable a page you set its execute bit by executing this shell command in a terminal:

chmod a+x yourpage.html

To enable Includes in the document root you EITHER turn on the Directive Options Includes OR you add these two lines into the .htaccess file for the document root:

Options Includes
XBitHack on

The most common choice for rented web servers is to use .htaccess because that space is available to the user.

High Traffic Saturation: I employ file locking to stop counters from being corrupted by being addressed simultaneously by multiple calls from the Apache server. I have placed a miniscule time delay lock on the counter once it is called to prevent corruption. I estimate that if your site experiences more than 5 million hits per month then you might have to install a more sophisticated counting mechanism in order to avoid statistically significant under-counting.

Calling/displaying the list of counts: The special page "admin.html" will be located in your site at http://www.yoursite.com/counter/admin.html. Call it in your web browser and you should get a listing like this linked screenshot. Use this for admin purposes. It updates itself each time it's called/viewed.

Possible Errors:

  • Check the permissions on the directory "counter". Maybe make it drwxrwxrwx.
  • Sometimes you have to change Options Includes to Options +Includes
  • Get the file extension correct (htm/html) in thecode page_name.html.counter.
  • Make sure the page/s have the x-bit set.
  • Report any bugs, difficulties, ideas in the comment form.

Swerdna: 27 February 2008 ver 1.1 released. Ver 1.2 on 15 march 08.


Swerdna's Open Source

Lately I developed an interest in programming in C, FreeBasic and PHP. I hope you find these interesting and/or useful.

Safe Web Comments: A web page comment form protected from spam robots by Captcha & heuristic spam traps.

Web Hit Counter: A system for recording and displaying web page hits in an Apache web server

Preview: A graph plotting utility for visualising two dimensional serial numerical data

Comments:   

  Add Comments

Posted: 28 October 2008 by Rohit Sharma
Very good software. Unfortunately I am unable to see the screenshot of webhitcounter. PNG file is missing. Also - can admin.hsml file be renamed admin.shtml ? My apache webserver (with hosting service) parses shtml file just fine but not htmls for SSI.

Posted: 4 February 2008 by Swerdna from Oz
Help me test this: Post comments and questions here.