The eAuction Support Forums
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl
eAuction 1.6.1.x >> Start Up and more >> Hit Counter
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl?num=1162731418

Message started by mars on 11/05/06 at 13:56:58

Title: Hit Counter
Post by mars on 11/05/06 at 13:56:58

Dieter,
I would like to put a simple hit counter (prefer it to be hidden) on the main eAuction.pl page
I have been able to find any counters for perl pages, only html web pages.
Do you have any suggestions?

mars


Title: Re: Hit Counter
Post by Dieter Werner on 11/05/06 at 15:12:01

Hi mars,

what do you want to count?

- the current visitors of the site
or
- the total number of visitors
or
- the total number of clicks


Title: Re: Hit Counter
Post by mars on 11/05/06 at 15:21:10

Thanks Dieter,

I would like to count the number of persons that "hit or visit" the first/main page of the auction.

mars

Title: Re: Hit Counter
Post by Dieter Werner on 11/05/06 at 16:19:52

OK - I will try it ...

Title: Re: Hit Counter
Post by mars on 11/07/06 at 12:45:08

Dieter,
Danke.

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

mars

Title: Re: Hit Counter
Post by Dieter Werner on 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>";
}
###############################################################



Title: Re: Hit Counter
Post by mars on 11/09/06 at 14:27:29

Dieter,
Thank you for your revised and tested code. I will see what I can do with.
But I have another question that is an outshoot of wanting to put a counter on the main page.

I took the two eAuction 161 files (eConfig161.pl and eAuction.pl) and moved them to another directory, at the same level, in the cgi-bin. The only configuration I changed was the following:
FROM:
Quote:
# The cgi-bin subdirectory where your eAuction.pl will be stored
   $config{'auction_dir'}      = '2eAuction161';

TO:
Quote:
# The cgi-bin subdirectory where your eAuction.pl will be stored
   $config{'auction_dir'}      = '22eAuction161';


However when I go to that new URL and click on "My Auction-Center" and then attempt to log in like I do with the old URL I get the following error message:
Error
Regfile: Antenen
could not be opened


I am confused because all of the other configurations are unchanged and I expected that the moved auction files would still find the required data files where they still remain.

Regards,
mars

Title: Re: Hit Counter
Post by Dieter Werner on 11/09/06 at 15:06:27


mars wrote:
I am confused because all of the other configurations are unchanged and I expected that the moved auction files would still find the required data files where they still remain.

No - that's not the case ...
when you change the content of $config{'auction_dir'}, the script creates another data directory.
So you have to copy the content(s) of the previous directory into the new directory.
It's not a bug - it's a feature  ;)

Title: Re: Hit Counter
Post by mars on 11/09/06 at 15:20:57

Dieter,


Quote:
It's not a bug - it's a feature


And a good feature it is. Thanks [smiley=thumbup.gif]  ;)

mars

The eAuction Support Forums » Powered by YaBB 2.2!
YaBB © 2000-2007. All Rights Reserved.