Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$ENV{'HTTP-REFERER'} problem

Status
Not open for further replies.

PhillC

Technical User
Jul 11, 2002
4
GB
Hi,

I need to check the referer of site visitors and I can't get HTTP-REFERER to yield any information at all. I've even copied and pasted code from perl.com which lists all the $ENV variables and their contents. Everything seems to work ok but still HTTP-REFERER reveals nothing.

I know that the referer should have some content because I've tried it with clicks from search engine listings and the referers appear in the log. I just can't get hold of the data from HTTP-REFERER.

Any help would be appreciated.

Phil.
 
I cringe to think of your response to this:
Are you typing HTTP-REFERER in your code?
Because it should be HTTP_REFERER

Run this script on your server:

#======== Script start
#!/path/to/perl

use CGI;
my $j = new CGI;
print $j->header();

print &quot;$_ => $ENV{$_} <br>\n&quot; for keys %ENV;
#======= End script

This will dump out the environment variables to your browser. Check out to make sure the one you want is there. Hopefully it's not a deep problem like server configuration.

EXACTLY how are you attempting to access the value?

--jim
 
Hi Jim,

Thanks for answering so quickly. I cringed when you mentioned the hyphen and underscore :)

$ref = $ENV{'HTTP_REFERER'};
$usr = $ENV{'HTTP_USER_AGENT'};

That's copied from the script I'm using, so it was ok. After that, I simply print $ref and $usr to a file. $ref prints ok but $usr prints a blank line.

I'd already run a loop script to print out all the $ENV variables and I've just run yours (much smaller and more elegant). They both produce the same result - no HTTP_REFERER in the list. It doesn't exist in the $ENV array.

It looks like a server config issue, huh? That's not a major problem as I have root access. But I've no idea what needs to be changed. Any ideas?

Phil.
 
What's your server? If it's apache, it's probably pretty simple. But I still don't really know how to do it.

So if I can't do a simple thing then what does that make me?

I kind of thought that it was one of those default environment variables that were just there. Since you don't have it (active) on yours, maybe it's 'disabled' somewhere.

Check out the httpd.conf file which is your configuration file (if it's apache). You could browse through that for any fun looking lines that might be setting up your environment.

--jim
 
It is Apache, Coderifous. I'll have a look in the httpd.conf file for any &quot;fun looking lines&quot;.

In the course of this I finally discovered how the redirect a visitor using PHP so, if I can't crack the perl problem, and if I can find out how to get the referer in PHP, I'll do it in PHP :)

Phil.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top