Gossamer Forum
Home : General : Perl Programming :

'HTTP_REFERER

Quote Reply
'HTTP_REFERER
Hi,

I would like to save all my redirects in the syntax "domain.com", alsow when it's www.domain.com/dir/sub/..../blabla.html

So I wrote the following line, but it returns: domain.com/ is some cases. Offcourse I could remove all "/" dor $partner but i think there must be a single line option.


my $partner = '';
$partner = $1 if $ENV{'HTTP_REFERER'} =~ /.*\.([^.]*\.[^.]*)/;


Quote Reply
Re: 'HTTP_REFERER In reply to
This will strip trailing and leading slashes...

$partner=~ s/(^\/)|(\/$)//g;

It is pretty easy to modify to just strip trailing slashes.

This should work....

$partner=~ s/(\/$)//g;



Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: 'HTTP_REFERER In reply to
After seaching on internet I copied my ($partner) = $ENV{'HTTP_REFERER'} =~ m,.+://([^/]+)/.*,;

But now I found out a bug (or feature) with this line in combination with my cookie script. If there's no referer the script just redirects without setting a cookie. But does this only happen with my netscape version or with all browsers; because then this is a great feature!






Code:
#!/usr/local/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use CGI;

my $in = new CGI;
my ($partner) = $ENV{'HTTP_REFERER'} =~ m,.+://([^/]+)/.*,;

my $cookie = $in->cookie(
-name => 'partner',
-value => $partner,
-domain => '.domain.com',
-expires => '+1d',
-path => '/'
);

print $in->redirect(
-url => 'http://www.test.com',
-cookie => $cookie
);

__END__


Quote Reply
Re: 'HTTP_REFERER In reply to
Yes I think this would happen with all browsers.

You may want to use....

#!/usr/local/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use CGI;my $in = new CGI;

if ($ENV{'HTTP_REFERER'}) {
my ($partner) = $ENV{'HTTP_REFERER'} =~ m,.+://([^/]+)/.*,;

my $cookie = $in->cookie( -name => 'partner',
-value => $partner,
-domain =>'.domain.com',
-expires => '+1d',
-path => '/'
);
print $in->redirect( -url => 'http://www.test.com',
-cookie => $cookie
);
}
else {

#SET SOME OTHER COOKIE

}










Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: 'HTTP_REFERER In reply to
actually.. if there is no $partner.. than its just deleting the cookie.. on some browsers it won't set and on some browsers it will set a cookie with a name but no value.

Jerry Su
widgetz sucks
Quote Reply
Re: 'HTTP_REFERER In reply to
Thanks jerry!

I wrote the following to have a least a default when there was no http_referer.

my $referer = $ENV{'HTTP_REFERER'} || 'http://default/';
my ($partner) = $referer =~ m,. ://([^/] )/.*,;