#!/bin/ksh # SSI Counter # Copyright © 1998 by David Ross (rossde@acm.org) typeset -L20 ipaddr typeset -L20 oldip typeset -R30 now typeset -i newsecs typeset -i oldtime # Get counter file name cntr_file=${HTTP_ross_cntrname}.dat # collect IP addresses of visitors ipaddr=$REMOTE_ADDR # time in seconds let newsecs=$(date -u +'%s') # Does file exist? if [ -a $cntr_file ]; then #yes read counter oldtime oldip < $cntr_file # read file else #no counter=0 # initialize counter oldip='000.000.000.000' oldtime=0 fi increment='yes' if (( $newsecs - $oldtime > 300 )); then # hit not recent let counter=$counter+1 # increment it elif [[ $ipaddr != $oldip ]]; then # from different visitor let counter=$counter+1 # increment it else increment='no' fi print $counter $newsecs $ipaddr > $cntr_file # save it to the file # Note: need new IP and time even if 'old' hit print 'Content-type: text/html' print '' print ' ' if [[ $increment == 'yes' ]]; then # add to log only for 'new' hit now=$(date) print "$ipaddr $now" $counter >> visit_${HTTP_ross_cntrname}.log fi