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

I'm having a problem setting multiple cookies at the same time in a mod_perl2 environment.

I'd like to do something like this:

my $cookie1 = CGI::cookie( "-name" => "foo", "-value" => "a" ); my $cookie2 = CGI::cookie( "-name" => "bar", "-value" => "3" ); $r->headers_out->{"Set-Cookie"} = $cookie1; $r->headers_out->{"Set-Cookie"} = $cookie2;

But I'm only seeing the second cookie reach the browser. The only solution I've found is to do this:

$r->headers_out->{"Set-Cookie"} = "$cookie1\nSet-Cookie: $cookie2";

Needless to say, this is really ugly and doesn't scale well to a larger number of cookies.

Is there some trick I'm missing?

Replies are listed 'Best First'.
Re: Multiple cookies under mod_perl2
by borisz (Canon) on Sep 02, 2004 at 17:24 UTC
    Add the second header.
    my $cookie1 = CGI::cookie( "-name" => "foo", "-value" => "a" ); my $cookie2 = CGI::cookie( "-name" => "bar", "-value" => "3" ); $r->headers_out->{"Set-Cookie"} = $cookie1; $r->headers_out->add("Set-Cookie" => $cookie2);
    Boris
Re: Multiple cookies under mod_perl2
by ikegami (Patriarch) on Sep 02, 2004 at 17:30 UTC