Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Help with Apache::Cookie

by neilwatson (Priest)
on Nov 02, 2003 at 20:25 UTC ( [id://303950]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks, I making a first attempt at setting and reading cookies. I seem to be able to set a cookie successfully:
my $r = Apache->request; Apache::Cookie->new( $r, name => 'license_session', value => $secret, path => '/', expires => '+8h', )->bake;
My real problem is in reading cookies:
my $cookie = Apache::Cookie->fetch; my $name = $cookie->name; my $value = $cookie->value; print "<h3>name = $name</h3>\n"; print "<h3>value = $value</h3>\n";

An error is returned: Can't call method "name" on an undefined value. This error points to the line where $name is defined. The documentation for apache::cookie is pretty small. Having read it, I thought this would be simple. What have I missed?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Help with Apache::Cookie
by arthas (Hermit) on Nov 02, 2003 at 21:18 UTC

    Hi!

    Apache::Cookie->fetch() returns an hash reference, not a Cookie object. The keys of the hash are the cookie names, while the values are the actual objects.

    Hope this helps!

    Michele.

      I still don't know what the syntax is supposed to be :(

      Neil Watson
      watson-wilson.ca

Re: Help with Apache::Cookie
by neilwatson (Priest) on Nov 03, 2003 at 18:00 UTC
    Success. Here is how to retreave a cookie:

    my $cookies = Apache::Cookie->fetch(); my ($name, $value); # 'license_session' is the name of the cookie # I am looking for. if ($cookies->{license_session}) { $name = $cookies->{license_session}->name(); $value = $cookies->{license_session}->value(); } print "<h3>name = $name</h3>\n"; print "<h3>value = $value</h3>\n";

    Neil Watson
    watson-wilson.ca

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://303950]
Approved by adrianh
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found