Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   How to concatenate cookies (http://www.velocityreviews.com/forums/t903040-how-to-concatenate-cookies.html)

dr_phill123@yahoo.com 05-11-2007 02:41 AM

How to concatenate cookies
 
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]);


Mumia W. 05-11-2007 04:35 AM

Re: How to concatenate cookies
 
On 05/10/2007 09:41 PM, dr_phill123@yahoo.com 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

dr_phill123@yahoo.com 05-11-2007 05:09 AM

Re: How to concatenate cookies
 
On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
+nos...@earthlink.net> 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 ``; " ?


Brian McCauley 05-11-2007 07:28 AM

Re: How to concatenate cookies
 
On 11 May, 06:09, dr_phill...@yahoo.com wrote:
> On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
>
> +nos...@earthlink.net> 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);


Mumia W. 05-11-2007 11:35 AM

Re: How to concatenate cookies
 
On 05/11/2007 12:09 AM, dr_phill123@yahoo.com wrote:
> On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
> +nos...@earthlink.net> 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.





All times are GMT. The time now is 10:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.