Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/articles/perl-tutorials/)
-   -   Perl Hit Counter (http://www.go4expert.com/articles/perl-hit-counter-t363/)

naveen 16Jun2005 12:00

Perl Hit Counter
 
Hi,
Perl has been very famous for providing with very small but very useful programs, especially for the web. Hit Counters are one of such domains. Here is a small perl code to implement a basic hit counter in a web page

Code: PERL

#!/usr/bin/perl -wT

print "Content-type:text/html\n\n";

$log = "count.dat";
open GETCOUNT, "<$log" or die("Error in $0: $log - $!n");
$hits = <GETCOUNT>;
close(GETCOUNT);

$hits++;
print "$hits people have viewed this website";

open COUNT, ">$log" or dienice("Cant open file to WRITE");
print COUNT $hits;
close COUNT;

Remember to create a file called count.dat with a default value of 0 in the same directory as the above program to store the number of hits. If you want to incorporate the program into another webpage, just copy it into that web page. Also remember to chmod the permission of count.dat to writable, else the program won't work.

shabbir 23Apr2009 15:48

Re: Perl Hit Counter
 
Simple PageViews Counter in PHP is also a nice logic


All times are GMT +5.5. The time now is 23:05.