How to concatenate cookies

Discussion in 'Perl Misc' started by dr_phill123@yahoo.com, May 11, 2007.

  1. Guest

    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]);
     
    , May 11, 2007
    #1
    1. Advertising

  2. Mumia W. Guest

    On 05/10/2007 09:41 PM, 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
     
    Mumia W., May 11, 2007
    #2
    1. Advertising

  3. Guest

    On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
    > 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 ``; " ?
     
    , May 11, 2007
    #3
  4. On 11 May, 06:09, wrote:
    > On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
    >
    > > 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);
     
    Brian McCauley, May 11, 2007
    #4
  5. Mumia W. Guest

    On 05/11/2007 12:09 AM, wrote:
    > On May 10, 11:35 pm, "Mumia W." <paduille.4061.mumia.w
    > > 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.
     
    Mumia W., May 11, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,544
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,560
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    683
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. _Who
    Replies:
    7
    Views:
    2,725
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    917
Loading...

Share This Page