Provides an interface to Netscape (HTTP/1.1) cookies that can be used in conjunction with or independently. To use CGI::Cookie, create a new cookie object with the constructor new. You can then send the cookie to the browser in one of the following ways:

  • From a CGI script, create a Set-Cookie field in the HTTP header for each cookie you want to send ($c is the cookie object):

    print "Set-Cookie: $c0";
  • With (see Chapter 10), use the header method with a -cookie argument:

    print header(-cookie=>$c);
  • Using mod_perl (see Chapter 11), use the request object’s header_out method:


    The following methods are provided for CGI::Cookie.

Get Perl in a Nutshell, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.