Using CGI::Cookie

Discussion in 'Perl Misc' started by Jason Carlton, Nov 29, 2009.

  1. For CGI::Cookie, Cpan states:

    The simplest way to send a cookie to the browser is by calling the bake
    () method:
    $c->bake;

    If you want to set the cookie yourself, Within a CGI script you can
    send a cookie to the browser by creating one or more Set-Cookie:
    fields in the HTTP header. Here is a typical sequence:

    my $c = new CGI::Cookie(-name => 'foo',
    -value => ['bar','baz'],
    -expires => '+3M');

    print "Set-Cookie: $c\n";
    print "Content-Type: text/html\n\n";


    When should I use "bake", and when should I simply use "Set-Cookie"?
    Is there an advantage or disadvantage either way?

    The script I'm building doesn't actually print anything to the screen,
    but just redirects to a success page. Since there's no content-type
    being printed, does this mean that I need to use bake?

    TIA,

    Jason
    Jason Carlton, Nov 29, 2009
    #1
    1. Advertising

  2. Jason Carlton

    Todd Wade Guest

    On Nov 28, 8:55 pm, Jason Carlton <> wrote:
    > For CGI::Cookie, Cpan states:
    >
    > The simplest way to send a cookie to the browser is by calling the bake
    > () method:
    >   $c->bake;
    >
    > If you want to set the cookie yourself, Within a CGI script you can
    > send a cookie to the browser by creating one or more Set-Cookie:
    > fields in the HTTP header. Here is a typical sequence:
    >
    >   my $c = new CGI::Cookie(-name    =>  'foo',
    >                           -value   =>  ['bar','baz'],
    >                           -expires =>  '+3M');
    >
    >   print "Set-Cookie: $c\n";
    >   print "Content-Type: text/html\n\n";
    >
    > When should I use "bake", and when should I simply use "Set-Cookie"?
    > Is there an advantage or disadvantage either way?


    This is an excellently formatted question! But a peek at the source
    will probably answer the question easily for you:

    http://cpansearch.perl.org/src/LDS/CGI.pm-3.48/lib/CGI/Cookie.pm

    It looks like one may want to use bake for a couple different reasons.
    Possibly for consiseness in the client code, or where the code may be
    used in different environments (CGI and mod_perl in particular).

    trwww
    Todd Wade, Dec 2, 2009
    #2
    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. Ben
    Replies:
    3
    Views:
    5,831
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Replies:
    2
    Views:
    466
  3. David Heinemeier Hansson
    Replies:
    3
    Views:
    137
    David Heinemeier Hansson
    Oct 24, 2004
  4. Paul  Wolpe
    Replies:
    0
    Views:
    164
    Paul Wolpe
    Oct 17, 2005
  5. Xeno Campanoli
    Replies:
    2
    Views:
    136
    Xeno Campanoli
    Jul 10, 2008
Loading...

Share This Page