neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

I have set a cookie successfully using:
# set cookie Apache::Cookie->new( $r, name => 'license_session', value => $sid, path => '/', expires => '30m', )->bake;

What I can't understand I how to get the cookie, and its data, back?

Update In more detail, here is my main code:

<%args> $uname => 'x' $passwd => 'x' $url </%args> <%perl> use warnings; use strict; use lib "/var/www/itiv/modules"; use Mapps::Session; use Mapps::Auth; ########################## # try to authenticate ########################## my ($auth, $uid) = Mapps::Auth::auth($uname, $passwd); if ($auth == 1){ my $s = Mapps::Session->new(); my $sid = $s->new_session($uid); #my $sid = $s->sid(); # set cookie Apache::Cookie->new( $r, name => 'session', value => $sid, path => '/', expires => '30m', )->bake; #print "sid = ".$sid; my %cookies = Apache::Cookie->fetch; my $csid = $cookies{'session'}->value; print " sid = ".$sid; print "<br>csid = ".$csid; exit;
$sid and $csid should be the same. However, they are not. Can anyone tell me why?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Getting data using Apache::Cookie
by Fletch (Bishop) on Aug 04, 2004 at 18:50 UTC

    perldoc Apache::Cookie, look for the fetch class method.

    Update: Also the parse and value instance methods.

      Fetch gets the whole cookie? How do you get a specific piece from the fetched cookie? Is that was parse does?

      Given the cookie in my first post:

      my $cookies = Apache::Cookie->fetch(); my $value = $cookies->value;
      This does not work.

      Neil Watson
      watson-wilson.ca

        See the example from the libapreq source.

        ... my $r = shift; my $apr = Apache::Request->new($r); my $cookies = Apache::Cookie->new($r)->parse; my $c = $cookies->{'animals'}; my %zoo = (); %zoo = $c->value if $c; ...