QuickTopic free message boards logo
Skip to Messages

TOPIC:

A local Daypop Top 40?

8
Glenn Fleishman
03-06-2002
02:37 PM ET (US)
That last part got munged because QuickTopic sucks a href's out. It should read

print OUT "
followed by a <
then an a href=
then a backslash "
then
$pages[$i]</a> ($count[$i])<br>\n";
7
Glenn Fleishman
03-06-2002
02:36 PM ET (US)
This was intriguing, so i wrote some hacky code that could be improved.

#!/usr/bin/perl

local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
@MoY = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$logstamp = sprintf ("%2.2d/%s ", $mday, $MoY[$mon]);
$host = "glennf.com";
$path = "/usr/www/glenns";
$logpath = "/usr/apache13/logs/httpd-log.all.hosts";

# assumes Extended Log Format with the host name in the first position,
# like www.boo.com
open (LOG, "< $logpath");
while (<LOG>) {
 next unless (/ 200 /);
 (@line) = split / /;
 local ($page) = $line[7];
 local ($ref) = $line[11];
 $ref =~ s/^\"([^\"]+)\"$/\1/;
 #print "$page, $ref\n";
 next if ($line[0] !~ /$host/ || $ref eq "-" || $ref =~ m://(www|\.)$host/:i || $ref !~ m|^http\://|i || $page =~ /\.xml$/);
 $toppage{$page}++;
}
close LOG;

local ($i);
foreach (sort { $toppage{$b} <=> $toppage{$a} } keys %toppage) {
   push @count, $toppage{$_};
   if (m|/$|) { $_ .= "welcome.html"; }
   local ($key) = $_;
   local ($title);
   if (-e "$path$key") {
 open (IN, "< $path$key");
 while (<IN>) {
    if (/<title>([^<]+)/i) {
  $title = $1;
  last;
    }
 }
 close IN;
   }
   if (!$title) { $title = $key; }
   $title{$title} = $key;
   push @pages, $title;
   $i++;
   last if $i > 10;
}
open (OUT, "> toppages.txt");
print OUT "<!-- start $logstamp -->\n";
print OUT "<p>";
foreach ($i = 0; $i <= 10; $i++) {
   print OUT "<a href=\"$title{$pages[$i]}\">$pages[$i]</a> ($count[$i])<br>\n";
}
print OUT "</p>\n";
print OUT "<!-- end $logstamp -->\n";
close OUT;
exit;
Edited 03-06-2002 02:36 PM
6
Cory Doctorow
03-05-2002
08:29 PM ET (US)
Thanks, Matteo!
5
matteo
03-05-2002
01:26 PM ET (US)
a quick PHP way :

<?

$new = $HTTP_SERVER_VARS["HTTP_REFERER"];
if ($new !eregi("mysite.com")){
$file="/somewhere/top_pop.txt";
$fd = fopen ($file, "a");
if (flock($fd, 2)) {
fwrite($fd, $new);
flock($fd, 3);
fclose($fd);
}
}


?>

add this to all your pages and you get a realtime count..
4
brucee
03-05-2002
11:52 AM ET (US)
Webalizer does this sort of stuff. The search term "dead rat" has been in the top 20 search hits for chunder.com for eternity!
3
Chris SmithPerson was signed in when posted
03-05-2002
11:43 AM ET (US)
As you write it, don't blow up on missing HTTP_REFERER entries. People using local HTTP proxies often block this because of the tracking capability. I will sometimes re-enable it if I think the site is worth it, but that's my decision. Interestingly, sites that depend on this info rarely fail gracefully. They just sort of blow up in slow motion.,

That said, the number of people blocking it is likely small enough to leave the stats being meaningful.
2
Cory Doctorow
03-05-2002
11:43 AM ET (US)
Assume they're ginmormous (i.e., 1,000,000+ visitors/day)
1
Kickstart
03-05-2002
11:33 AM ET (US)
How big are the log files?

Print | RSS Views: 1340 (Unique: 736 ) / Subscribers: 1 | What's this?