Here's how I do it:
This JavaScript is written to the page:
<script type="text/javascript" language="JavaScript">
<!--
document.write("<img src=\"ref.cgi?refer=");
document.write(escape(document.referrer));
document.write("\" width=1 height=1>");
// -->
</script>
This CGI runs on the server (Pip.png is a 1 pixel graphic):
#!/usr/bin/perl
use CGI qw(:standard);
my $pip = '/path/to/pip.png';
my $logf = '/path/to/referrer.log';
my $ref = param("refer");
open(LOG, ">>$logf");
print LOG $ref;
close(LOG);
open(PIP, "<$pip");
undef $/;
my $pixel = <PIP>;
close(PIP);
$/ = "\n";
print header( -type=>'image/png' );
binmode(STDOUT);
print STDOUT $pixel;
exit;
|