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

Hi, I'm trying to get the http referer, but as yet, have not been able to. So far I have tried these: $ENV{HTTP_REFERER} $ENV{HTTP_REFERRER} As yet, I have only been able to get my address from the variable, or nothing. Even when I follow a link pointing to my site from another site. How in the world do you get the referer address via perl??? I'm wanting this so that I can see where visitors are comming from. If there accessing the site directly, I would expect the the veriable to be blank, but if there following a link from another site, then there should be something in the variable, and that should be there refering site, not my site. Sure, one can fake this, but I doubt all sites (even google) would be faking this. Perhaps there is simply some other veriable that I'm over looking.

Replies are listed 'Best First'.
Re: Getting the http referer
by Zaxo (Archbishop) on Mar 15, 2005 at 09:34 UTC

    $ENV{'HTTP_REFERER'} should get it if the header is present. It may not be, depending on the browser and how it acquired the url.

    After Compline,
    Zaxo

Re: Getting the http referer
by gellyfish (Monsignor) on Mar 15, 2005 at 11:29 UTC

    Before you start relying on the Referer header you probably want to look at the section on Security Considerations in the HTTP Specification: many firewall and proxy vendors have taken this on board and you will often find the Referer header removed or obliterated in the request. This is particularly common with popular "desktop firewall" and "internet privacy" software.

    /J\

      There are also some browsers which have an option to supress the referrer. (It used to be that they were way too liberal with information given -- the early versions of Netscape used to send your e-mail address with every request, and the referer header with whatever the last page you were on, even if it you weren't following a link.)

      You might want to try a different browser, and see if you continue to have the same problem. Oh -- and the correct spelling is the misspelled one -- %ENV{'HTTP_REFERER'}. You can check all of the variables that you have to work with something like:

      warn map { sprintf "%20s : %s\n", $_, $ENV{$_} } sort keys %ENV;

      (will send to your webserver's error log, unless you've changed where STDOUT STDERR goes)

      Update: STDOUT != STDERR. (shouldn't post before I've had my morning caffeine.. thanks manav for the catch)

        Not STDOUT but STDERR....

        Manav
        Thanks. I located the problem. The issue was with the site being in frames, and the code to grab the info, was in a framed page, thus I was getting the site as a refered since the main frame page was calling the sub html/cgi. Putting a SSI call to a cgi script to get the info works fine.

        Any chance someone knows how i can set a new var to the browser so that all page calls will have the info, without using a dummy form?
Re: Getting the http referer
by jbrugger (Parson) on Mar 15, 2005 at 09:33 UTC
    If you just want to see where visitors come from, use a log-file analyser like awstats, wwwstat, analog, webdruid or webalizer. (There are much more).
    It would be nice to see on what os you are, to see what fits your needs best.