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

I want to be able to set the HTTP_REFERER Enviroment variable. I've tried using the following

$ENV{'HTTP_REFERER'}  "http://www.rt4all.com";

and if I use

print $ENV{'HTTP_REFERER'};

from the same piece of code it works ok. When I use the print from the cgi program I am calling the http_referer field is blank, I'm calling it by opening a new window using javascript and html

print "Content-type: text/html\n\n"; print <<"HTML code"; <SCRIPT language=JavaScript> function openwind() { win1=window.open('http://www.ringtones4all.com/cgi/topsite.cgi?value=$ +member', '',config='height=800,width=600') } </script>

Edit kudra, 2002-05-09 Fixed unclosed CODE tag, new title

Replies are listed 'Best First'.
Re: http_referer
by hopes (Friar) on May 09, 2002 at 07:08 UTC
    Do you want to fetch a url?
    Use LWP::UserAgent.
    You can set the HTTP_REFERER, user-agent, manage cookies, etc.
    Example:
    use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("yourownnavigator/0.1 "); my $req = new HTTP::Request POST => 'http://www.yoursite.com/yourpage. +pl'; $req->header(Referer => 'http://www.yourothersite.com/default.pl'); my $res = $ua->request($req); if ($res->is_success) { print $res->content; }


    Hopes
    $_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s, $_^=q,$\^-]!,,print
Re: http_referer
by tadman (Prior) on May 09, 2002 at 08:08 UTC
    First, something truly awful happened to your post and it's all plaintextified-HTML. Yikes! Looks like a runaway <CODE> tag. Don't forget about the "Preview" button, neh?

    The HTTP_REFERER(sic) is set by the browser at its own discretion. There are occasions, like using JavaScript to open a window, where the browser decides not to send that information to you at all. If it's not sent, you can take a wild guess as to where they came from, but it's not very reliable unless you have a user-specific cookie and they are using a single window.

    Just as a note, you can't set the referrer inside the browser using JavaScript, nor can you tell the browser what the referer "should" be using Perl. It's just one of those things you don't have much control over.
(cLive ;-) Re: http_referer
by cLive ;-) (Prior) on May 09, 2002 at 10:15 UTC
    This not a Perl issue, but a javascript one - OT though it is, it's also hard to answer without knowing the context in which openwind is called? href? onclick? etc.

    document.referrer in JS is a read only do element (yes, it is spelt differently!)

    Instead of opening the script direct in the window, open a dummy page that calls the script (eg, ...<body onload="document.href=... etc "><h3>Loading</h3>...). That should send a referer.

    If this is a security measure, it's poor security - LWP::UserAgent can fake HTTP_REFERER easily. I suggest you drop that and use a session cookie instead.

    But with no context or explanation why, it's just my...

    .02

    cLive ;-)

      Did you test your example? There seems to be a mistake in your JavaScript syntax, as href is a property of location, not of document itself, so the command should be written like this:

      document.location.href='http://www.your-url.test'

      In addition it should be said that when changing location using JavaScript, Netscape (4.x) browsers will send a referrer, Internet Explorer (5 / 6) will not. I did not yet test what Netscape 7 / Mozilla does. Most of my customers use Internet Explorer on a Windows machine.

        No, JavaScript I detest, not test :)

        cLive ;-)

        --