6.08.2006

CGI Cookies

Assuming that we're inside a module or something, and this is being passed to us as arguments:

Prelimary



use CGI;
use strict;
my $query = new CGI;
my $cookie;

...

sub writeCookie {
my($expires,$name,$contents,$rememberBoolean) = @_;
if($rememberBoolean) {
$expires = "+6M"; ## give them a 6 month remembered period
} else {
$expires = ""; ## delete the cookie after the browser has been closed
}
$cookie = $query->cookie(
-name=>$name,
-value=>$contents,
-expires->$expires
);
print $query->header(-cookie=>[$cookie]);
}

No comments: