At 22:35 06.06.2001 -0500, you wrote:
> > I too have a question about this.
> > below is the code:
> >
> > open(A,">>/home/thx-1138/cgi-bin/data/refs.htm");
> > print A "$ENV{'HTTP_REFERRER'}\n";
> > close (A);
> >
> > The file opens, prints a return/linefeed and closes...
> >
> > any ideas why this wont work???
> > it looks correct to me from what i have read.

It does work -- HTTP_REFFERER doesn't exist, or is an empty string.  Also 
FYI, you don't need the single quote (or double quotes) inside the curly 
brackets for hash keys -- save yourself the quoting trouble and write:
$ENV{HTTP_REFERRER}

>I'm no where near being an expert at perl (and know even less about the 
>rules for file I/O), but I'm pretty sure two things could be
>wrong here:
>1) The "$ENV{'HTTP_REFERRER')\n"; part for sure doesn't work because it's 
>only interpolated this way if $ENV = "Joe" (for example's
>sake):
>
>The file A would have this written in it:
>"Joe('HTTP_REFERRER')"
>
>I'm not that good at explaining things, but perl can't interpolate things 
>like that.  It thinks that the parameters you're passing
>are instead text.  To fix it, do this:
>
>print A $ENV('HTTP_REFERRER') . "\n"; #note how the first part isn't in 
>quotes, that's how the interpolation went wrong last time

%ENV is a hash, and needs to be handled as such, ie. curly brackets.  The 
above example is incorrect.
Probably, nothing got printed out to A because the HTTP_REFERRER key 
contained an empty string or didn't exist.  If you want to have a look at 
everything living inside the %ENV hash, add this to the top of your cgi script:

print "$_:  $ENV{$_}<br>\n" foreach keys %ENV;

If I run that off my own computer (Win2000, Apache) I don't get an 
HTTP_REFERRER key -- because I've called the cgi script directly, so there 
is no referral.

>2) Maybe $ENV('HTTP_REFERRER') is blank?  If so, like I told the last 
>person, use CGI.pm and do this:
>
><perl>
>use CGI qw(:standard escapeHTML);
>$IP = remote_host();
>open (A,">>/home/thx-1138/cgi-bin/data/refs.htm");
>print A $IP . "\n";
>close (A);
></perl>
>
>I hope that helped more than it confused you.  If you need any more help, 
>feel free to ask.


remote_host is not the same as HTTP_REFERRER, is it? -- http referral is 
the address of the server where the page lives that the person clicked on 
to arrive to the cgi script.  It should also be treated with a grain of 
salt, as the information it provides can easily be manipulated and forged 
to make it look like the request is coming from a different computer.  You 
shouldn't use http referral alone for security, for instance.
Aaron Craig
Programming
iSoftitler.com

Reply via email to