PDA

View Full Version : HTTP_REFERER diffs


bazz
02-21-2005, 07:30 PM
Hi,

I run a script which can be called by any (Qualified list), website. SO when you access the script from a page in their site the HTTP_REFERER should work fine. I should add, that this script outputs an html page where the variables have been called from a flat file db.

However.....As my script loads, it calls on a .pm file so that the script loads a header and footer to make the script output match the calling site.

What I see is that the outputted script shows tha referer to be my site, when I want to be able to read the domainname.com from the incoming site.

Progress in thought even, is difficult as I am losing track the steps my coding needs to take.

Thinking so far....(It is a question itself);

My script should call the HTTP_REFERER from the incoming site?
Then it should pass it to the .pm file in a hidden input so that it knows that it is the external site and not miine, that is calling the script.

Then the .pm file can run as coded to provide the appropriate header and footer to integrate the outputted html with that external sitres appearance.

But, surely I can't write to a .pm file; surely it is simply called as is? So how then can I get information to it (such as http_referer) so that it can work out which page has called it?


Here's the .pm file - It works in as much as the defalt header will load. That's because I haven't yet worked out how to tell it what it needs to know.


package includes;
# Header & footer module, includes.pm:

sub new(){
my $self=shift;
my %sites=(
'www.yourdomain.com'=>['../../../headers_and_footers/default/header.html','../../../headers_and_footers/default/footer.html'],
'www.anotherdomain.co.uk'=>['../../../headers_and_footers/chris/header.html','../../../headers_and_footers/chris/footer.html']
);
my @files=((exists $sites{$ENV{'REMOTE_HOST'}})?(@{$sites{$ENV{'REMOTE_HOST'}}}):('../../../headers_and_footers/default/header.html','../../../headers_and_footers/default/footer.html'));
bless \@files,$self;
}

sub header(){
return showfile($_[0]->[0]);
}

sub footer(){
return showfile($_[0]->[1]);
}

sub showfile{
local $/;
open(my $file,$_[0]) or die 'Can\'t open '.$!;
my $content=<$file>;
close($file);
return $content;
}

1;


BTW, I have tried different ENV variables with not the correct success.

REMOTE_HOST
SERVERNAME
HTTP_REFERER

I would rather not use cookies for just one reason. I haven't had time to try them and I need this done sort of, well, today (if possible). :rolleyes:


Bazz

mlseim
02-21-2005, 07:40 PM
Bazz ...

I think you should install cookie.lib, chmod to 755 and let me know.

It's time to use cookies. That would be a great solution to your
REFFERER problem.

--max--

bazz
02-21-2005, 09:00 PM
OK, I'll go back and read now what you sent me a couple of days ago. Shall see how I get on.


Bazz

mlseim
02-21-2005, 09:11 PM
Once you get cookie.lib installed and the domain name set to yours,

1) Pick the first script that the correct $ENV-"whatever" appears at.

2) Put this at the top of your script:

require 'cookie.lib';
&SetCookies('user_ref','$ENV{'REMOTE_HOST'}'); #or whatever it is ...

3) Then, on any other script that you need to read the cookie ...

4) Put this at the top of that script:

require 'cookie.lib';
&GetCookies('user_ref');
$user_ref = $Cookies{'user_ref'};

5) Now, $user_ref will be the original cookie value.

You can &Set and &Get cookies for anything you can think of ...

Good Luck!

--max--