RE: CGI Counter

by Jason <dawgclan(at)shaw.ca>

 Date:  Thu, 04 Apr 2002 16:11:45 -0800
 To:  Website Help List <hwg-techniques(at)hwg.org>
 In-Reply-To: 
  todo: View Thread, Original
Hmmmm Thanks for the Script Kenneth but It's not working.
http://dawgclan.vectorstar.net/test.html contains just the Exec CGI
counter and nothing else on page, and it's not running. And would anyone
know how to store all the I.P's in a database? I would really like to do
that, I was talking to a teacher at school today and that=92s what he
suggested, and it makes for quicker read time. And 1 file. Sounds good
to me. If anyone can help please speak up.
Here is the New Counter Source.
http://dawgclan.vectorstar.net/cgi/newcounter.txt
Here is the Perl Script
http://dawgclan.vectorstar.net/cgi/counter.pl
Thanks
Jason

-----Original Message-----
From: Kenneth Dombrowski [mailto:printer2(at)designmattersinc.com]=20
Sent: April 4, 2002 2:28 PM
To: 'Jason'
Subject: RE: CGI Counter


Jason,

Sorry it took so long to get back to you, a busy day @ work..

The attached script is a revised version of yours.=20

In addition to what you asked for, the script now creates separate
counters for each page you put it on, I assumed this was desirable
behavior.

I also assumed you are including the output onto your page via the #exec
cgi syntax.

It updates only once per IP per page. An added bonus is you get a log of
all the ips visiting each page. This isn't managed in a very
conservative way, however, it's going to store every ip for every page;
16 bytes per page per ip... When disk space becomes an issue you'll save
some space if you put them in a central file & reference them in the
page-specific files by line number

Or set the whole thing up to use berkeley db or something similar

The script dies early if the page accessing it does not live on a server
configured in @legal_servers;
One of the first things you'll probably want to do is change line 24
'255.255.255.255' to your server's ip.=20
I don't think any other config will be necessary.

If you're using this on a heavily trafficed site, I would suggest you
read about locking with semaphore files:
http://perl.plover.com/yak/hw1/Hardware-notes.html#Semaphore_Files

Also, one possible glaring weakness is line 52. I'm not sure what
happens if mkdir is called and the path to the directory includes other
directories that have not been made... Maybe it's okay, maybe it'll
fail. You can either read up on it & fix it if necessary, or be careful
that the required directories exist manually... If you do end up
updating it, I'd be interested in seeing it=20

I Hope it works for you,

Kenneth



-----Original Message-----
From: owner-hwg-techniques(at)hwg.org [mailto:owner-hwg-techniques(at)hwg.org]
On Behalf Of Jason
Sent: Wednesday, April 03, 2002 6:44 PM
To: Website Help List
Subject: CGI Counter



Sorry about that here is the cgi source.
http://dawgclan.vectorstar.net/cgi/counter.txt
and the real script is http://dawgclan.vectorstar.net/cgi/counter.cgi
I would like to make it log once per I.P and also make it usable only on
my domain. Thanks Jason _________________________________________
Jason
Dawgclan Network
ICQ#: 48569749
Website: http://dawgclan.vectorstar.net
_________________________________________

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA