Gossamer Forum
Home : General : Perl Programming :

$in->header;

Quote Reply
$in->header;
Hi,

Thanks to Paul I could add a crypt-function to the following script. (Thanks, Wink) Only now still one thing needs to be solved. It's the following:

If a user hits this script with a referer the referer is set. this part works fine (see code explanation) But is NO referer is found a empty cookie is set; in other words the existing one is overwritten with " ". How can I make sure NO cookie is set in that case?

(I don't know how to switch from print $in->header( -cookie => $cookie ); to print $in->header();)

Code:


my $in = new CGI;
my $id = $in->param('ID');

my $referer = $ENV{'HTTP_REFERER'} || 'http:// /'; # I use http:// / due to the next line.
my ($value) = $referer =~ m,.+://([^/]+)/.*,; # clean referer into www.domain.com
my $crypt = join ("\-", map { ord } (split //, $value)); # change into number-number-number and so on
if (length($crypt) < 5) { $crypt = ""; } # makes sures that not a space is set, see line 1

my $cookie = $in->cookie(
-name => 'userkey',
-value => $crypt,
-domain => '',
-expires => '+16h',
-path => '/'
);

print $in->header( -cookie => $cookie );
&site_html_detailed_frameset($id);


__END__
Quote Reply
Re: [cK] $in->header; In reply to
How about:

print $referer ? $in->header( -cookie => $cookie ) : $in->header();
Quote Reply
Re: [cK] $in->header; In reply to
Quote:

my $crypt = join ("\-", map { ord } (split //, $value));

There's no need to escape the "-" here, just use "-" instead of "\-".

- wil
Quote Reply
Re: [Wil] $in->header; In reply to
Cool, thanks for all help.

But I just found out that the following two lines ate not really working. For example: www.domain.com (without ending /) does set a cookie! Does anyone know a code to get the referer and clean everything out and only leave behind "prefix's.domain.com"? Would be handy.

Code:


my $referer = $ENV{'HTTP_REFERER'} || 'http:// /'; # I use http:// / due to the next line.
my ($value) = $referer =~ m,.+://([^/]+)/.*,; # clean referer into
www.domain.com


Quote Reply
Re: [cK] $in->header; In reply to
Change:

my $referer = $ENV{'HTTP_REFERER'} || 'http:// /';

to:

my $referer = $ENV{'HTTP_REFERER'};

and:

my ($value) = $referer =~ m,.+://([^/]+)/.*,; # clean referer into www.domain.com

to:

my $value = $referer;
$value =~ s|^http://([^/]+).*|$1|i;

Last edited by:

Paul: Jun 1, 2002, 2:08 AM