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

Ok, I need to embed a hit counter-type script in an html file with SSI. But in this script, I need to get the referer url to the html file. that doesnt seem to make any sense, so ill try this:
Referer Document --> Html Document --> CGI Script
i need to, from the script, get the referer to the html document. I tried the environmental HTTP_REFERER, but from the script, the variable was blank. I just need to get the variable recorded on the server somehow...and if it helps, i'm SSI-ing the script with an "exec cgi=" command.

Replies are listed 'Best First'.
Re: SSI pain...
by thinker (Parson) on Aug 26, 2002 at 07:59 UTC
    Hi,

    Have you tried passing HTTP_REFERER as an argument to your counter, from the ssi. For example
    <--#exec cmd="/bin/counter HTTP_REFERER"-->
    then shift()ing the arguement in the counter.

    Hope this helps

    cheers

    thinker
      i tried that, but putting HTTP_REFERER in the cmd just passes the text string "HTTP_REFERER"...is there any way to define that as a variable *inside* the cmd command?

        Please don't use SSI's cmd, it can be dangerous. You can read more about SSI here.

        What's wrong with DOCUMENT_URI?

        Ciao, Valerio

        You probably need to add a sigil at least, as in $DOCUMENT_URI. I'm not sure, but you may also need to use a question mark as in <!--#include virtual="/cgi-bin/foo.cgi?$DOCUMENT_URI" --> (Note that this places the string in @ARGV, not $ENV{QUERY_STRING}.)

        Makeshifts last the longest.

Re: SSI pain...
by valdez (Monsignor) on Aug 26, 2002 at 10:40 UTC

    You are right, HTTP_REFERER is not set, but instead you can use DOCUMENT_URI.

    Ciao, Valerio