Operating System - Linux
1748169 Members
4296 Online
108758 Solutions
New Discussion юеВ

Re: HTTP_REFERER gets undefined

 
Ron Barak
Advisor

HTTP_REFERER gets undefined

Hi All,

I need to solve a problem in Perl/5.8.0 vis-a-vis Apache/2.0.40.

I have a Perl CGI script that calls another Perl CGI script.
In the first script HTTP_REFERER is defined, but once the second script is called, HTTP_REFERER gets undefined.

Any idea why this is happening ?

Thanks,
Ron.
7 REPLIES 7
Stuart Browne
Honored Contributor

Re: HTTP_REFERER gets undefined

Given that HTTP_REFERER is just part of the GET or POST request headers, are you sure the first CGI is passing it on?
One long-haired git at your service...
Ron Barak
Advisor

Re: HTTP_REFERER gets undefined

Hi Stuart,

IMHO, the HTTP_REFERER is not part of the request headers, but is an environment variable (since it is retrieved by Perl's $ENV{'HTTP_REFERER'}).

What I cannot understand is why in the first script, the environment contains a valid HTTP_REFERER -
while during the execution of the called (second) script, HTTP_REFERER suddenly becomes undefined ?!

Bye,
Ron.
Stuart Browne
Honored Contributor

Re: HTTP_REFERER gets undefined

an environment variable? Then it's extremely specific to the way your scripts are written. Time to learn perl.

Are you doing mod_perl stuff or just CGI's written in perl?
One long-haired git at your service...
Ron Barak
Advisor

Re: HTTP_REFERER gets undefined

Hello Stuart,

A quote from http://www.perlfect.com/articles/cgi_env.shtml
--------------------------------------------
CGI Environmental Variables
One of the methods that the web server uses to pass information to a cgi script is through environmental variables. These are created and assigned appropriate values within the environment that the server spawns for the cgi script. They can be accessed as any other environmental variable, like with getenv() (in C) or %ENV{'VARIABLE_NAME'} (in Perl). Many of them, contain important information, that most cgi programs need to take into account.

This list, highlights some of the most commonly used ones, along with a brief description and notes on possible uses for them. This list is by no means a complete reference; many servers pass their own extra variables, or having different names for some, so better check with your server's documentation. The purpose of this list is only to suggest some common good uses for some of the server-passed information.

...

HTTP_REFERER
The URL that the referred (via a link or redirection) the web client to the script. Typed URLs and bookmarks usually result in this variable being left blank.
In many cases a script may need to behave differently depending on the referer. For example, you may want to restrict your counter script to operate only if it is called from one of your own pages, to prevent someone from using it from another web page without your permission. Or even, the referer may be the actual data that the script needs to process. Extending the example above you might also like to install your counter to many pages, and have the script figure out from the referer which page generated the call and increment the appropriate count, keeping a separate count for each individual URL. A snippet for the referer blocking example could be:

die unless($ENV{HTTP_REFERER}=~m/http:\/\/(www\.)?$mydomain\//);
------------------------------------------
So, it may be I need to go back and learn Perl, but others share my faulty Perl knowledge ;-)

Ron.

Stuart Browne
Honored Contributor

Re: HTTP_REFERER gets undefined

Ur huh, that's fine, but it doesn't say *WHERE* the referer comes from.

When in a GET or POST request, a conversation can look similar to this:

GET http://domain.com/path/to/file.html HTTP/1.0
Host: domain.com
Referer: http://domain.com/paht/from.html

The 'Referer:' header there is what gets thrown into HTTP_REFERER on the server side.

What this means is that if you have one script calling another script, the first script has to supply the referer it's self. It won't just 'magically' get there.
One long-haired git at your service...
Matti_Kurkela
Honored Contributor

Re: HTTP_REFERER gets undefined

Ron, what exactly do you mean with "a CGI script that calls another CGI script"?

I think this can mean several things, and we are not necessarily all thinking about the same variety.

In the first CGI script, you can give the client something (a redirect, or some tag in the content) that makes the client request the second CGI script. In this case, the client may have special rules about when the referrer information is sent and when it is not.
For example, the client may choose not to send the referrer information for privacy reasons if the second script is requested from a different domain than the first one.

Or you can make the first script call the second script on the server side, giving it suitably-formed input and parsing the output, then integrating it into its own output.

There might be other ways.

So, exactly how are you implemented the calling of the second script?
MK
Ron Barak
Advisor

Re: HTTP_REFERER gets undefined

Hi Matti,
I decided to get the information I needed from a source other that HTTP_REFERER, as it seems to be unreliable for my purposes.
Thanks in anycase, and points are due.
Bye,
Ron.