need counter help
by "eric williams" <eric_alt(at)hotmail.com>
|
Date: |
Sat, 01 Jul 2000 17:16:52 PDT |
To: |
hwg-languages(at)hwg.org |
|
todo: View
Thread,
Original
|
|
This variation of Cliffs counter was working fine for over a week on an NT
server, then suddenly last night it started filling the output file with
megabytes of invisible characters. Dont know if its the code or the
server...anybody see an error?
$logpath = "d:/americancatholicchurch_org/data/count.shtml";
$epath = "d:/americancatholicchurch_org/data/dataf.shtml";
$adpath = "d:/americancatholicchurch_org/data/admin.shtml";
$visible = 0;
$pad = 5;
@valid_uri = ("d:/americancatholicchurch_org");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
$year += 1900;
$date = "$months[$mon] $mday, $year";
if(length($hour)<2){$hour = "0$hour"};
if(length($min)<2){$min = "0$min"};
if(length($sec)<2){$sec = "0$sec"};
open (LOG, $logpath )or &dienice( "Can't read data from $logpath \n");
@data = <LOG>;
close(LOG);
$url = "<tr><td align=\"right\"><a
href=\"$ENV{'SCRIPT_NAME'}\">$ENV{'SCRIPT_NAME'}</a>:</td>";
$count = 0;
$pad = "%.$pad"."d";
#print a count for each page. In counter log file.
open (LOG, ">$logpath")or &dienice("Can't write data to $logpath \n");
foreach $line(@data) {
if ($line =~ /$url/) {
$line =~ /<td>(.*)<\/td>/;
$count = $1;
$count++;
$count = sprintf($pad, $count);
print LOG "$url<td>$count<\/td><\/tr>\n";
}
elsif ($count == 0 && substr($line,0,8) eq "</table>") {
$count++;
$count = sprintf($pad, $count);
print LOG "$url<td>$count<\/td><\/tr>\n";
print LOG "$line";
}
else { print LOG "$line\n"; }
}
close(LOG);
#Dump environment variables to visitor log file.
# http://whois.arin.net/cgi-bin/whois.pl
open (DATAF,">>$epath")or &dienice("Can't write to $epath \n");
print DATAF "$date $hour:$min:$sec   *   $count   *   <a
href=\"$ENV{'SCRIPT_NAME'}\">$ENV{'SCRIPT_NAME'}</a>   *  
$ENV{'REMOTE_ADDR'}   *   <a
href=\"$ENV{'HTTP_REFERER'}\">$ENV{'HTTP_REFERER'}</a>   *  
$ENV{'HTTP_USER_AGENT'}  *   $ENV{'HTTP_ACCEPT_ENCODING'}   *
  $ENV{'HTTP_ACCEPT_LANGUAGE'}   *   $ENV{'REMOTE_PORT'}<p>\n";
close (DATAF);
if ($visible) {
print "Content-type: text/html\n\n";
print "<table class=\"main\" width='750'><tr><td
colspan=\"3\"><\!--\#include virtual \= 'counter_include.inc'--><br><font
color='white'><b>\ $count<\/b><\/font><\/td><\/tr><\/table>\n";
}
#&dump($errmsg);#unconditional screen dump
if ($errmsg){&dump($errmsg);}#if there is an error dump info to screen
exit;
#end main program
sub dump{
print "Content-Type: text/html\n\n";
print "\n $ENV{SCRIPT_NAME} shows $count hits on $date at $hour : $min :
$sec GMT-4<br>\n";
print "last error was $errmsg<br>\n";
print "Listing of all available environment variables<br><hr>\n";
#the next 3 lines will show all available environment variables
while (($key,$value) = each %ENV) {
print "$key = $value<br>\n";
}
return;
}
sub dienice {
($errmsg) = @_;
print <<EndHTML;
<html><body><br><h2>Error</h2>$errmsg<br></body></html>
EndHTML
;
return;
}
exit;
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA