Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Multiple Cookies with CGI::Application

by sedhed (Scribe)
on Jul 28, 2002 at 03:16 UTC ( #185801=note: print w/replies, xml ) Need Help??


in reply to Re: Multiple Cookies with CGI::Application
in thread Multiple Cookies with CGI::Application

Well, yes, kinda. Cookies are name=value pairs, when you get down to it. But using CGI.pm, one doesn't really use them directly that way.

perldoc CGI says:

The interface to HTTP cookies is the cookie() method: $cookie = $query->cookie(-name=>'sessionID', -value=>'xyzzy', -expires=>'+1h', -path=>'/cgi-bin/database', -domain=>'.capricorn.org', -secure=>1); print $query->header(-cookie=>$cookie);

In the example, $cookie is actually a hashref, or more accurately, a CGI::Cookie object.

Now to pass multiple cookies, you use a ref to an anonymous array, containing the cookie objects you wish to pass. CGI.pm continues:

To create multiple cookies, give header() an array reference: $cookie1 = $query->cookie(-name=>'riddle_name', -value=>"The Sphynx's Questio +n"); $cookie2 = $query->cookie(-name=>'answers', -value=>\%answers); print $query->header(-cookie=>[$cookie1,$cookie2]);

Hope this clarifies things a little.

cheers!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://185801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-01-18 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?