[PLUG] Counter Code

Pat Finnegan finnegpt@purdue.edu
Thu, 12 Apr 2001 12:53:25 -0500


This is a multi-part message in MIME format.
--------------A67E624C87F27A5F0FCFFEF5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Search on freshmeat.net for "web counter" or whatever you want to find
stuff for.  Attached is a sample counter program i made in C.

Zach Markley wrote:

> Is their a good online resource to learn how to make your own counter
> for a web site and track who views your site?
>
> Thanks,
> Dave
>
> --
> "I don't make jokes. I just watch the government and report the facts."
> Will Rogers
>
> Zach Markley and/or Dave
> The Crash Car Star
> markley@purdue.edu
> ____________________________________________________
> The Purdue Linux Users' Group (PLUG) mailing list.
> For account maintenance, go to:
> plug mailing list  -  plug@csociety.purdue.edu
> http://csociety.ecn.purdue.edu/mailman/listinfo/plug

-- Pat

I didn't like the play, but I saw it under adverse conditions.  The curtain
was up.
   - fortune(5)



--------------A67E624C87F27A5F0FCFFEF5
Content-Type: text/plain; charset=us-ascii;
 name="count.cgi.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="count.cgi.c"

/**************************************************************
 * 
 * counter.cgi.c:
 *     Implements a hit counter for a web page.  To use,
 *     make the page using this a server-parsed html page
 *     (eg. index.shtml), and add the following shtml to
 *     the page:
 *     <!--#exec cgi="/cgi-bin/count.cgi" -->
 *     The above tag will get parsed by the server and replaced
 *     with the output of the cgi script.
 * 
 * Copyright (C) 1999-2001 Patrick Finnegan.
 * 
 * You can do whatever you want with this code EXCEPT copyright it
 * or register a patent/trademark based on anything in this program,
 * or the methods used by this program.
 ***************************************************************/

#include <stdio.h>

#define CTR_FILE "/var/lib/apache/purdueriots.com/counter.db"

int main() {
   
   FILE *fctr;
   int count=0;
   
   if (fctr = fopen(CTR_FILE,"r")) {
      fscanf(fctr, "%d", &count);
      fclose(fctr);
   }
   
   count++;
   
   fctr = fopen(CTR_FILE,"w");
   fprintf(fctr, "%d\n", count);
   fclose(fctr);
   
   printf("Content-type: text/html\n\n");
   printf("Congrats, you are visitor #%d to this site.\n", count);
   
   return 0;
}

--------------A67E624C87F27A5F0FCFFEF5--