Gossamer Forum
Home : Products : Links 2.0 : Customization :

Showing REAL Hits instead of last-build-hits

Quote Reply
Showing REAL Hits instead of last-build-hits
To show the realtime hits (and not the hits of the last build), you can do it with an SSI-Call to a script like the clicks.cgi I wrote, this is a clone of the jump.cgi:

Code:

#!/usr/bin/perl
# To show the real clicks on site
# Required Librariers
# --------------------------------------------------------
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
# ========================================================
my %in = &parse_form();
my ($goto, $id, $delim, $time);

my $queryparams = $ENV{QUERY_STRING};
my ($param1, $param2) = split(/&/,$queryparams);
my ($key1,$pageid) = split(/=/,$param1);
my ($key2,$visits) = split(/=/,$param2);
my $realcount = $visits;

my $id = $in{$db_key};
my $delim = quotemeta($db_delim);
my $time = time();

if (exists $in{$db_key}) {

# look for new visitors and print the counter
print "Content-type: text/html\n\n";
### new visitors?
if (open (HIT, "<$db_hits_path/$id")) {
my ($count, $old_time, @IP, $ip, $visited);
chomp ($count = <HIT>);
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}

######## yes
$realcount = $visits + $count;
print "$realcount\n";
}
### no
else {
$realcount = $visits;
print "$realcount\n";
}
}
else {
&error ("No link specified!");
}

sub error {
# ------------------------------------------
#
print "Error: $_[0]\n";
exit;
}




In your templates links.html or detailed.html, you have to change "Hits: <%hits%>" to:

Code:

Hits: <!--#include virtual="/cgi-bin/clicks.cgi?ID=<%ID%>&VISITS=<%hits%>"-->



Hope it works for you! Perhaps the solution can be made a little bit more elegant, I am not very good in writing PERL (and not very good in writing in english, too).

On my site, I also use an expanded version of clicks.cgi for not only showing the hits, but also increase the hits-counter, because on this site I want to count the visitors to the detailed pages and not the people who click on the url.

Greetings from Cologne, Germany
Cyriaxx