in reply to Multiple Cookies with CGI::Application

Your problem lies in the basic fact that cookies are unique value pairs. You would need to pass in a scalar value rather than an array (either $c1 or $c2 or $c3 or the three concatenated together.

Hope this helps. :-)
  • Comment on Re: Multiple Cookies with CGI::Application

Replies are listed 'Best First'.
Re: Re: Multiple Cookies with CGI::Application
by sedhed (Scribe) on Jul 28, 2002 at 03:16 UTC

    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!