How to concatenate cookies

D

dr_phill123

I would like to send multiple cookies in one variable, however the
code below just send one cookie:

for (my $j=0 ; $j<@custom_fields; $j++) {
$cookie_custom_fields .= $query->cookie(-domain=>$domainname,
-name=>"custom$j",
-value=>"$in_field[$j]" ) . ', ';
}
print $query->header(-cookie=>[$cookie_custom_fields]);
 
M

Mumia W.

I would like to send multiple cookies in one variable, however the
code below just send one cookie:

for (my $j=0 ; $j<@custom_fields; $j++) {
$cookie_custom_fields .= $query->cookie(-domain=>$domainname,
-name=>"custom$j",
-value=>"$in_field[$j]" ) . ', ';
}
print $query->header(-cookie=>[$cookie_custom_fields]);

You can put several values into a single cookie like so:

my $cookie = $query->cookie(
-domain => $domainname,
-name => 'customfields',
-value => \@custom_fields
);
print $query->header(-cookie => $cookie);


Read the CGI docs again: perldoc CGI
 
D

dr_phill123

You can put several values into a single cookie like so:

my $cookie = $query->cookie(
-domain => $domainname,
-name => 'customfields',
-value => \@custom_fields
);
print $query->header(-cookie => $cookie);

Read the CGI docs again: perldoc CGI

Thanks, but I am actually looking for each cookie to be seperate, so
have multiple cookies in one variable $cookie. The docs says:

you may concatenate the cookies together with ``; ''

I am not sure what those characters mean ``; " ?
 
B

Brian McCauley

Thanks, but I am actually looking for each cookie to be seperate, so
have multiple cookies in one variable $cookie. The docs says:

you may concatenate the cookies together with ``; ''

I am not sure what those characters mean ``; " ?

I'd guess they'd mean a literal semicolon (whereas you had a comma).

But one of my top rules of programming is "always use the most natural
representation of things". The most natural type of variable to
represent a list of things is an array (not a delimited string).

my @cookie_custom_fields;
for my $j ( 0 .. $#custom_fields ) {
push @cookie_custom_fields => $query->cookie(-domain=>
$domainname,
-name=>"custom$j",
-value=>"$in_field[$j]" );
}
print $query->header(-cookie=>\@cookie_custom_fields);
 
M

Mumia W.

Thanks, but I am actually looking for each cookie to be seperate, so
have multiple cookies in one variable $cookie. The docs says:

you may concatenate the cookies together with ``; ''

I am not sure what those characters mean ``; " ?

What docs are you talking about? I can't find that exact language in
either CGI.pm's POD, or in RFC2109. In RFC2109, something close to the
syntax you talk about is described, but I can't find anything that
suggests that CGI.pm supports that.

The description of raw_cookie() is a little confusing. While you can get
cookies which have been concatenated with "; " (semicolon and space)
from CGI::raw_cookie(), there does not seem to be a way to create such
cookies.

Anyway, RFC2109 says that cookies are separated by commas:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top