Baz has asked for the wisdom of the Perl Monks concerning the following question:

Thnx everyone for your replies, i found it all very helpful. I tried out the $ENV{'HTTP_REFERER'} variable and it returned the calling html file. But what i really desire is the ability to discover what sites ppl are linking from to come to mine. In other words, whats the referer of my index.html. I think i remember reading somewhere about the use of an index.cgi......this could include the $ENV{'HTTP_REFERER'} and would return what im looking for. Can this be called in 'parallel' to index.html, or to put it another way, if i have both index.html and index.cgi in a paricular directory which of the two files is the default for that directory.
Again thanks everyone, and particular thanks to jcwren, who saved my from the per'ls of tripod and its many disabled $ENV values
  • Comment on Site Statistics using $ENV{'HTTP_REFERER'}

Replies are listed 'Best First'.
Re: Site Statistics using $ENV{'HTTP_REFERER'}
by George_Sherston (Vicar) on Sep 21, 2001 at 00:56 UTC
    I don't know if you've considered this and rejected for some other reason, but somewhere on your web server, in a dir probably called logs there shd be a file called something like access.log, and that likely has the same info you get from $ENV{'HTTP_REFERER'} for all the files called from your server, including index.html. Then all you need is a perl app to parse the file and throw you the results :). (But I see this is part of a longer inquiry, and if this sounds like I'm teaching my grandmother to suck eggs then I apologise.)

    § George Sherston
Re: Site Statistics using $ENV{'HTTP_REFERER'}
by blakem (Monsignor) on Sep 21, 2001 at 02:14 UTC
Re: Site Statistics using $ENV{'HTTP_REFERER'}
by perrin (Chancellor) on Sep 21, 2001 at 01:26 UTC
    May I suggest you take a gander at some of the fine books O'Reilly has on HTTP and CGI? You could try "CGI Programming with Perl, 2nd Edition" or "Webmaster in a Nutshell, 2nd Edition". Once you understand the basics of HTTP and configuring a webserver, this stuff will be easy for you.
Re: Site Statistics using $ENV{'HTTP_REFERER'}
by Beatnik (Parson) on Sep 21, 2001 at 01:29 UTC
    That information isn't saved by the HTTP protocol... You can however try sending a hidden field containing a javascript call to document.history. Since I'm no JS guru, I'll leave it at that.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      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;