Using CGI::Cookie

J

Jason Carlton

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
 
T

Todd Wade

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
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top