eAuction
  Not just another Perl script
Google
Welcome, Guest. Please Login or Register


If you use eAuction a lot and like it or if you make money from eAuction or from eAuction-related activities ...
then the project asks you for a donation in favor of the further development.



The forums are protected by
AccessControl
(written by Dieter Werner)
Click here if you want to check your IP against the most important RBLs of the net.
Click here in order to visite the AccessControl forums.


<< Visit the international e Auction Marketplace >>
Buy and sell PC and Consumer Electronic components






  HomeHelpSearchLoginRegister
 



Pages: 1 2 3 
Hit Counter (Read 488 times)
Dieter Werner
Administrator
*****
Online

Dipl. Paranoiac ®

Posts: 1162
Germany
Gender: male
Re: Hit Counter
Reply #3 - 11/05/06 at 16:19:52
 
OK - I will try it ...
Back to top
 
 

Multimedia file viewing and clickable links are available for registered members only!!  You need to Login or Register!!


Greetings from Germany
Dieter Werner




Advertising
View Profile | WWW   IP Logged
mars
eAuction Expert
Tester
***
Offline

I love Perl

Posts: 149

Re: Hit Counter
Reply #4 - 11/07/06 at 12:45:08
 
Dieter,
Danke.

I will give it try this week and let you know the results.

mars
Back to top
 
 


Advertising
View Profile   IP Logged
Dieter Werner
Administrator
*****
Online

Dipl. Paranoiac ®

Posts: 1162
Germany
Gender: male
Re: Hit Counter
Reply #5 - 11/08/06 at 16:50:11
 
Hi mars,

the following code should be the better one - and it has been (local) tested now.
I think, it should work ...
Code:
###############################################################
sub hit_counter {
###############################################################
   my $database = $config{'basepath'};
   my $datafile = $database . 'hitcount.dat';
   my $ip_timeout = 86400; # 24 hours
   my $visitor = $ENV{'REMOTE_ADDR'};
   my ($ip, $old_time, $totals);
   my %visitors;
   local $_;
   
   # We create the data directory (unless it exists)
   do {
	  umask(000);
	  mkdir "$database", 0755;	  
   } unless -d $database;
   
   # We create the data file (unless it exists)
   do {	  
	  open CNT_FILE, "> $datafile" or die $!;
	  print CNT_FILE "0\n";
	  close CNT_FILE;
   } unless -e $datafile;
   
   # We open the data file and lock it
   open CNT_FILE, "+< $datafile" or die $!;
   flock CNT_FILE, 2 or die $!;
   
   # We read the total number of past visitors
   $totals = <CNT_FILE> || 0;
   chomp $totals;
   
	  while (<CNT_FILE>) {
		chomp;
		($ip, $old_time) = split /,/;		
		$visitors{$ip} = $old_time;
	  }	  
   
   # We eliminate double clicks from the same IP
   exists $visitors{$visitor}
	  ?   (((time - $visitors{$visitor}) <= $ip_timeout) && ($visitors{$visitor} = time))
	  :   do {
		    $visitors{$visitor} = time;
		    $totals++;
		};
   
   seek CNT_FILE, 0, 0;
   truncate CNT_FILE, 0;
   
   # We store the number of real visitors
   print CNT_FILE "$totals\n";
   
   # We restore the visitors which are inside the IP-Timeout
	  foreach $ip (keys %visitors) {
		((time - $visitors{$ip}) >= $ip_timeout) && next;
		print CNT_FILE "$ip\,$visitors{$ip}\n";
	  }
	  
   close CNT_FILE;
   
   # Just for testing ...
   print "<hr>Hits: $totals<hr>";
}
###############################################################




Back to top
 
« Last Edit: 11/09/06 at 11:18:58 by Dieter Werner »  

Multimedia file viewing and clickable links are available for registered members only!!  You need to Login or Register!!


Greetings from Germany
Dieter Werner




Advertising
View Profile | WWW   IP Logged
Pages: 1 2 3 


If you like eAuction, please Rate it.
If you don't like eAuction, please Rate it too.


1 is being poor and 10 is being excellent


EveryScript

ip-location


AccessControl - Members Only