Thread: Hit Counter

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    UK
    Posts
    49
    Rep Power
    14

    Hit Counter


    Hi,
    How do I go about putting a hit counter up on a website?

    Thanks
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Do you want to write your own or get a free one from somewhere else? If you just want a free one google has a bunch of suggestions: http://www.google.com/search?&q=free%20hit%20counter
  4. #3
  5. watch for flying fingers
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Rocket City, USA
    Posts
    819
    Rep Power
    378

    writing one: Perl


    Make a file count.cgi in your cgi-bin:

    Code:
    #!/usr/bin/perl
    
    our $count;
    
    open (INFILE,"./count.txt");
    while(<INFILE>){
    &nbsp;&nbsp;&nbsp;&nbsp;$count = $_;
    }
    close INFILE;
    
    print "<table><tr><td>$count visitors so far!</td></tr></table>\n";
    
    $count++;
    open(OUTFILE,">./count.txt");
    print OUTFILE "$count";
    close OUTFILE;
    Then, wherever you want the html code to go, do:

    Code:
    <!--#exec cgi="http://mysite.com/cgi-bin/count.cgi"-->
    EDIT: closing my filehandle!
    Last edited by linuxChique; September 30th, 2003 at 04:42 PM.
  6. #4
  7. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    You should lock your files as well, because this will get borked under concurrent accesses. It will lose or corrupt data.
  8. #5
  9. sardonyx quinx
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    156
    Rep Power
    12
    Try to register at http://copyandpastescripts.com

    They have a lot of cool services there

IMN logo majestic logo threadwatch logo seochat tools logo