#!/usr/bin/perl
use CGI qw(:standard :form);
####### CONFIG #######
$log_file_dir = qq(logs);
##### END CONFIG #####
print "Content-Type: text/html\n\n";
$query = new CGI();
$action = $query->param('action');
if($action eq "view_stat") { &view_stat; }
else { &wr_daily_count; }
sub wr_daily_count {
&all_count;
$day_counter_file = "$log_file_dir/".sys_date();
open(DAYCOUNTER, "$day_counter_file");
$today_hits = <DAYCOUNTER>;
close(DAYCOUNTER);
$today_hits += 1;
open(DAYCOUNTER, ">$day_counter_file");
print DAYCOUNTER "$today_hits\n";
close(DAYCOUNTER);
}
sub all_count {
$all_counter_file = "$log_file_dir/all.count";
open(ALLCOUNTER, "$all_counter_file");
$all_hits = <ALLCOUNTER>;
close(ALLCOUNTER);
$all_hits += 1;
open(ALLCOUNTER, ">$all_counter_file");
print ALLCOUNTER "$all_hits\n";
close(ALLCOUNTER);
}
sub view_stat {
print qq(
<HTML>
<HEAD><TITLE>Yupapa Visitor Stats</TITLE></HEAD>
<BODY>
Yupapa Stats:<P>
);
chdir($log_file_dir);
$counter = 0;
foreach (<*>) {
chomp;
if(-f $_) {
open(STATFILE,"$_");
$stat = <STATFILE>;
close(STATFILE);
if($_ ne "all.count") {
print qq($_ statistic: $stat<BR>);
} else {
print qq(<B>All Hits: $stat</B><BR>);
}
$counter++;
}
}
if(!-f "all.count") { print qq(There is no statistic available); }
print qq(
</BODY>
</HTML>
);
}
sub sys_date {
@days = ('1','2','3','4','5','6','7');
@months = ('1','2','3','4','5','6','7','8','9','10','11','12');
@en_month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = 1900 + $year;
$month = $en_month[$mon];
$today = "$month-$mday-$year";
return $today;
}
__END__
PM me, aim me at ejiant, or email me at elanb@removethispartbevcauseofspamhotpop.com.Originally posted by GRiN
Is there any counter out there that uses MySQL database and is something similar to this?
One that can count both hits for the day and hits in total would also be nice.
Yes, I've searched both HotScripts.com and PHP Resource Index.
Originally posted by triad web host
there is one in php and mysql at http://www.proxy2.de the site is down now for some reason but i have used it in past and it works great it also logs the ip address of the last 25 ppl in a small popup which u click on the counter and it shows up or u can disable that feature
Originally posted by GRiN
I've tried YUPAPA's script and it works great!
Will it reset itself automatically like other scripts, though?
#!/usr/bin/perl
####### CONFIG #######
$log_file_dir = qq(logs); # Directory where you store Logs (MUST BE WRITABLE)
$day_display = 10; # Display number of days on the stats page
##### END CONFIG #####
print "Content-Type: text/html\n\n";
print qq(
Yupapa Stats:<P>
);
$counter = 1;
open(DAYCOUNTER,"$log_file_dir/daily.dat");
while(<DAYCOUNTER>) {
chomp;
($day,$count) = split(/\|/, $_);
$all_counter += $count;
if($counter <= $day_display) {
print qq($day statistic: $count<BR>);
}
$counter++;
}
close(DAYCOUNTER);
if($counter == 1) { print qq(There is no statistic available); }
print qq(
<P>
All Visits: $all_counter
);
__END__
#!/usr/bin/perl
####### CONFIG #######
$log_file_dir = qq(logs); # Directory where you store Logs (MUST BE WRITABLE)
##### END CONFIG #####
print "Content-Type: text/html\n\n";
&wr_daily_count;
sub wr_daily_count {
$day_counter_file = "$log_file_dir/daily.dat";
open(DAYCOUNTER, "$day_counter_file");
while(<DAYCOUNTER>) {
chomp;
($day,$count) = split(/\|/,$_);
if($day eq sys_date()) {
$today_hits = $count + 1;
$saved_thing .= "$day|$today_hits\n";
$found_record = 1;
} else {
$saved_thing .= "$_\n";
}
}
close(DAYCOUNTER);
open(DAYCOUNTER, ">$day_counter_file");
if(!$found_record) {
print DAYCOUNTER sys_date()."|1\n";
}
print DAYCOUNTER $saved_thing;
close(DAYCOUNTER);
}
sub sys_date {
@days = ('1','2','3','4','5','6','7');
@months = ('1','2','3','4','5','6','7','8','9','10','11','12');
@en_month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = 1900 + $year;
$month = $en_month[$mon];
$today = "$month-$mday-$year";
return $today;
}
__END__
Um...make it as an include?Originally posted by GRiN
Thanks YUPAPA.
Is there a way to execute the script with PHP?