CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: mod_perl:
Extract a cookie value based on a variable?

 



rrhill
New User

Jul 2, 2007, 5:53 PM

Post #1 of 2 (11674 views)
Extract a cookie value based on a variable? Can't Post

I can extract a cookie using a literal has key name:

sub get_cookie {
my $r = shift;
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
return $cookies{"test"};
}

But I want to extract the cookie using a variable name rather than a literal key name:

sub get_cookie {
my $r = shift;
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
return $cookies{$cookie_name};
}

This isn't working.


KevinR
Veteran


Jul 2, 2007, 8:39 PM

Post #2 of 2 (11672 views)
Re: [rrhill] Extract a cookie value based on a variable? [In reply to] Can't Post

not sure what your question has to do with mod_perl, but your code looks like it should work OK. Try setting the value of $cookie_name to 'test' and see if it works.

sub get_cookie {
my $cookie_name = 'test';
my $r = shift;
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
return $cookies{$cookie_name};
}
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives