diff options
author | 1999-06-30 13:50:48 +0000 | |
---|---|---|
committer | 1999-06-30 13:50:48 +0000 | |
commit | 35642157dc5b17bb06f803189ab9c7dff01c7425 (patch) | |
tree | 77090a2927e11d2db14c87ab82b4dc255a3ecbe9 /html/counter.php3 | |
parent | af6dbb36ead642ca9ea346fbb6ac18d980280704 (diff) |
Simple hit counter
Diffstat (limited to 'html/counter.php3')
-rw-r--r-- | html/counter.php3 | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/html/counter.php3 b/html/counter.php3 new file mode 100644 index 00000000..285dc88d --- /dev/null +++ b/html/counter.php3 @@ -0,0 +1,43 @@ +<?php +/* + * Increment an access counter. + * David Aspinall, June 1999. + * + * $Id$ + * + */ + +$counterFile = "counter.txt"; +$counterStart = "counterstart.txt"; +$maxlen = 10; + +// NB: probably have trouble with permissions +// if file doesn't exist already, so start with +// empty files made with touch. + +if (is_readable($counterFile) && is_writeable($counterFile)) { + $fp = fopen($counterFile,"r+"); + if (filesize($counterFile)<1) { + // Start counter, write a timestamp. + $num = 1; + if (is_readable($counterStart) && is_writeable($counterStart)) { + $fps = fopen($counterStart,"w"); + fputs($fps,time()); + fclose($fps); + print "<!-- Hit counter initialized. -->"; + } else { + print "<!-- Hit counter initialized, but timestamp could not be set -->"; + }; + } else { + $num = fgets($fp,$maxlen); + $num += 1; + print "<!-- Hit counter: $num -->"; + }; + rewind($fp); + fputs($fp,$num); + fclose($fp); +} else { + print "<!-- Hit counter file $counterFile cannot be accessed. -->"; +}; +?> + |