How to Add Your Own Counter Script If you're ready to run a script on your server, you can write your own, or use the one below (written by CNET.COM Web Site Engineer Matt Rotter, for his "ABCs of CGI" feature). You can find another good counter script at Matt's Script Archive (no relation to Matt Rotter), which is an excellent source of free Perl scripts for many uses. Adding the script to your site isn't such a big deal. Step one Create a document called count.txt and place it somewhere on your server. Step two Create a file called counter.cgi including the code below. Be sure to replace /your/path/count.txt in the second line with the path to your own count.txt document. (Save the counter.cgi file to your server. Many servers have a standard place to keep such scripts, called cgi-bin. Also, be sure the first line of the script points to the server's Perl interpreter. It's typically at /usr/bin/perl, but it may not be. Check with your ISP if you are not sure.) #!/usr/bin/perl $count_file = "/your/path/count.txt"; if (-e "$count_file") { open(COUNT,"$count_file"); $file = ; chop($line) if $line =~ /\n$/; close(COUNT); ($date,$hit) = split(/\|/,$file); } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"); $date = "@months[$mon] $mday, \'$year"; $hit = "0"; open(COUNT,">$count_file"); print COUNT "$date\|$hit"; close(COUNT); } $new_count = $hit; $new_count++; open(COUNT,">$count_file"); print COUNT "$date\|$new_count"; close(COUNT); print "Content-type: text/html\n\n"; print "This page has been accessed $new_count times "; print "since $date"; Make sure the permissions are set correctly for count.txt and counter.cgi--the server must be able to write to count.txt and be able to execute counter.cgi. Step three When you've created the counter.cgi file and put the count.txt in place, add the piece of text below to the HTML of the page you want the counter to appear on. (This text is a server-side include, which is supported by most servers. Check with your ISP if you run into problems.) Be sure to replace the /path/to/cgi statement with the real location of your counter script. This code calls the counter.cgi script and places the current total in your HTML page. Note that you can edit the text that it returns by altering the Perl script.