Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to concatenate cookies

Reply
Thread Tools

How to concatenate cookies

 
 
dr_phill123@yahoo.com
Guest
Posts: n/a
 
      05-11-2007
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]);

 
Reply With Quote
 
 
 
 
Mumia W.
Guest
Posts: n/a
 
      05-11-2007
On 05/10/2007 09:41 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
dr_phill123@yahoo.com
Guest
Posts: n/a
 
      05-11-2007
On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
(E-Mail Removed)> wrote:
> 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 ``; " ?

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      05-11-2007
On 11 May, 06:09, (E-Mail Removed) wrote:
> On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
>
> (E-Mail Removed)> wrote:
> > 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 ``; " ?


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);

 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      05-11-2007
On 05/11/2007 12:09 AM, (E-Mail Removed) wrote:
> On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
> (E-Mail Removed)> wrote:
>> 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 ``; " ?
>


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:
> Informally, the Set-Cookie response header comprises the token Set-
> Cookie:, followed by a comma-separated list of one or more cookies.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Concatenate/De-Concatenate Carlos VHDL 10 10-24-2012 01:04 PM
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM



Advertisments