[vox-tech] Trying to use Apache::Cookie
Jay Strauss
vox-tech@lists.lugod.org
Wed, 21 May 2003 23:18:17 -0500
Ok, since it seems mod_perl is an appropriate topic. Here a mod_perl
question.
I'm trying to use Apache::Cookie. But I'm unable to send the cookie. I can
pick it up fine using Apache::Cookie->fetch (if I send it using
CGI::Cookie). I must not be doing something, like sending the header, or I'm
doing something else wrong. Below are 2 pieces of code the first is
supposed to create a cookie, the second fetches it and displays the keys.
Thanks
Jay
package Apache::Init;
use strict;
use Apache::Constants qw(:common);
use Apache::Cookie;
use CGI::Cookie;
use CGI qw/:standard/;
sub handler {
my $r = shift;
# If I do it like this it works
#
#my $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
#my $cookie2 = new CGI::Cookie(-name=>'preferences',
# -value=>{ font => 'Helvetica',
# size => 12 }
# );
#print header(-cookie=>[$cookie1,$cookie2]);
my $cookie = Apache::Cookie->new($r,
-name => 'foo',
-value => 'bar',
-expires => '+3M',
-domain => '.heyjay.com',
-secure => 1
);
$cookie->bake;
return OK;
}
1;
Second Code
===========
package Apache::Catch;
use strict;
use Apache::Constants qw(:common);
use CGI '-autoload';
use Apache::Cookie;
use CGI::Cookie;
sub handler {
my $r = shift;
my %cookies = Apache::Cookie->fetch;
map{$r->log_error($_); print "$_\n"} keys %cookies;
return OK;
}
1;
__END__