My Counter

I wrote this counter in perl. The images used can be easily made yourself, or you can search the internet for a set. www.digitmania.com used to be the best, but I'm not sure what happened to it. Now, I suggest searching in a search engine. Like this. For the code to work you need 10 seperate images named 0.gif to 9.gif.

The counter uses a graphic engine to load the images and return them. You can read the documentation and download this engine at the GD Graphics Library. The version of the GD engine I used supported gif images, and that's what I used in this example. But the current version no longer supports gifs because of problems with licensing, so you'll have to use jpgs or pngs instead, which will involve a little modifying of my code.

The counter uses two text files to keep track of the visits. It uses counter.txt and recent_visits.txt. You should start with creating these files as empty and adding "0\n0" to counter.txt. Also be sure to make these files readable and writeable by user, group, and other if using Unix. The counter.txt file has two lines. The first line is a number representing the hits displayed by the counter. The second line is a number which includes reloads. Reloads are not counted by storing the ip address and time of the current load in the recent_visits.txt file. If the current visit is in the recent_visits.txt file and has been within the timeout period specified at the top of the document (10 minutes in the current code), it isn't added to the first line, but is added to the second line. Otherwise a hit is added to both lines.

You can see the code here. You'll have to change the extension of the file to whatever your server supports, like .pl or .cgi.

Trackers

The above counter can easily be extended to tracking information from the accessing user. You just have to decide which information you want to track, come up with a way to get that information (if there is one), and come up with a method of storing the information.

I did this and wrote a tracker program which had most of the stuff found in other trackers out there. But I wrote this tracker at my previous job at Designouveau, so I can't provide the code. You can see the result here: http://www.designouveau.com/tracker/

In the future I may rewrite a new one that I can use and display the code here.


JavaScript | CGI Counter | Color Utility | Portfolio | E-mail me
Home | Family & Friends | Web Publishing | Cards For Sale
Copyright ©2001 Josh Birk. All rights reserved.