Programming :  Student Freelance Forum For Work Experience Builders' (CertificationPoint) The fastest message board... ever.
 
PERL-Handling Cookies
Posted by: adcertpoint (Moderator)
Date: April 29, 2020 04:37PM

Unless you use some well known module like CGI::Cookie or Apache::Cookie, you need to handle cookies yourself.

Cookies come in the $ENV{HTTP_COOKIE} variable. You can print the raw cookie string as $ENV{HTTP_COOKIE}.

Here is a fairly well-known bit of code to take cookie values and put them into a hash:
sub get_cookies {
# cookies are separated by a semicolon and a space, this will
# split them and return a hash of cookies
local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
local(%cookies);

foreach(@rawCookies){
($key, $val) = split (/=/,$_);
$cookies{$key} = $val;
}

return %cookies;
}

Or a slimmer version:
sub get_cookies {
map { split /=/, $_, 2 } split /; /, $ENV{'HTTP_COOKIE'} ;
}

Options: ReplyQuote


Sorry, only registered users may post in this forum.
This forum powered by Phorum.