diff options
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. -->"; +}; +?> + |
