Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / CGI::Cookie.3
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "CGI::Cookie 3"
.TH CGI::Cookie 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
.SH "NAME"
CGI::Cookie \- Interface to Netscape Cookies
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& use CGI qw/:standard/;
\& use CGI::Cookie;
.Ve
.PP
.Vb 7
\& # Create new cookies and send them
\& $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
\& $cookie2 = new CGI::Cookie(-name=>'preferences',
\& -value=>{ font => Helvetica,
\& size => 12 }
\& );
\& print header(-cookie=>[$cookie1,$cookie2]);
.Ve
.PP
.Vb 3
\& # fetch existing cookies
\& %cookies = fetch CGI::Cookie;
\& $id = $cookies{'ID'}->value;
.Ve
.PP
.Vb 2
\& # create cookies returned from an external source
\& %cookies = parse CGI::Cookie($ENV{COOKIE});
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
CGI::Cookie is an interface to Netscape (\s-1HTTP/1\s0.1) cookies, an
innovation that allows Web servers to store persistent information on
the browser's side of the connection. Although CGI::Cookie is
intended to be used in conjunction with \s-1CGI\s0.pm (and is in fact used by
it internally), you can use this module independently.
.PP
For full information on cookies see
.PP
.Vb 1
\& http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt
.Ve
.SH "USING CGI::Cookie"
.IX Header "USING CGI::Cookie"
CGI::Cookie is object oriented. Each cookie object has a name and a
value. The name is any scalar value. The value is any scalar or
array value (associative arrays are also allowed). Cookies also have
several optional attributes, including:
.IP "\fB1. expiration date\fR" 4
.IX Item "1. expiration date"
The expiration date tells the browser how long to hang on to the
cookie. If the cookie specifies an expiration date in the future, the
browser will store the cookie information in a disk file and return it
to the server every time the user reconnects (until the expiration
date is reached). If the cookie species an expiration date in the
past, the browser will remove the cookie from the disk file. If the
expiration date is not specified, the cookie will persist only until
the user quits the browser.
.IP "\fB2. domain\fR" 4
.IX Item "2. domain"
This is a partial or complete domain name for which the cookie is
valid. The browser will return the cookie to any host that matches
the partial domain name. For example, if you specify a domain name
of \*(L".capricorn.com\*(R", then Netscape will return the cookie to
Web servers running on any of the machines \*(L"www.capricorn.com\*(R",
\&\*(L"ftp.capricorn.com\*(R", \*(L"feckless.capricorn.com\*(R", etc. Domain names
must contain at least two periods to prevent attempts to match
on top level domains like \*(L".edu\*(R". If no domain is specified, then
the browser will only return the cookie to servers on the host the
cookie originated from.
.IP "\fB3. path\fR" 4
.IX Item "3. path"
If you provide a cookie path attribute, the browser will check it
against your script's \s-1URL\s0 before returning the cookie. For example,
if you specify the path \*(L"/cgi\-bin\*(R", then the cookie will be returned
to each of the scripts \*(L"/cgi\-bin/tally.pl\*(R", \*(L"/cgi\-bin/order.pl\*(R", and
\&\*(L"/cgi\-bin/customer_service/complain.pl\*(R", but not to the script
\&\*(L"/cgi\-private/site_admin.pl\*(R". By default, the path is set to \*(L"/\*(R", so
that all scripts at your site will receive the cookie.
.IP "\fB4. secure flag\fR" 4
.IX Item "4. secure flag"
If the \*(L"secure\*(R" attribute is set, the cookie will only be sent to your
script if the \s-1CGI\s0 request is occurring on a secure channel, such as \s-1SSL\s0.
.Sh "Creating New Cookies"
.IX Subsection "Creating New Cookies"
.Vb 7
\& $c = new CGI::Cookie(-name => 'foo',
\& -value => 'bar',
\& -expires => '+3M',
\& -domain => '.capricorn.com',
\& -path => '/cgi-bin/database',
\& -secure => 1
\& );
.Ve
.PP
Create cookies from scratch with the \fBnew\fR method. The \fB\-name\fR and
\&\fB\-value\fR parameters are required. The name must be a scalar value.
The value can be a scalar, an array reference, or a hash reference.
(At some point in the future cookies will support one of the Perl
object serialization protocols for full generality).
.PP
\&\fB\-expires\fR accepts any of the relative or absolute date formats
recognized by \s-1CGI\s0.pm, for example \*(L"+3M\*(R" for three months in the
future. See \s-1CGI\s0.pm's documentation for details.
.PP
\&\fB\-domain\fR points to a domain name or to a fully qualified host name.
If not specified, the cookie will be returned only to the Web server
that created it.
.PP
\&\fB\-path\fR points to a partial \s-1URL\s0 on the current server. The cookie
will be returned to all URLs beginning with the specified path. If
not specified, it defaults to '/', which returns the cookie to all
pages at your site.
.PP
\&\fB\-secure\fR if set to a true value instructs the browser to return the
cookie only when a cryptographic protocol is in use.
.Sh "Sending the Cookie to the Browser"
.IX Subsection "Sending the Cookie to the Browser"
Within a \s-1CGI\s0 script you can send a cookie to the browser by creating
one or more Set\-Cookie: fields in the \s-1HTTP\s0 header. Here is a typical
sequence:
.PP
.Vb 3
\& my $c = new CGI::Cookie(-name => 'foo',
\& -value => ['bar','baz'],
\& -expires => '+3M');
.Ve
.PP
.Vb 2
\& print "Set-Cookie: $c\en";
\& print "Content-Type: text/html\en\en";
.Ve
.PP
To send more than one cookie, create several Set\-Cookie: fields.
.PP
If you are using \s-1CGI\s0.pm, you send cookies by providing a \-cookie
argument to the \fIheader()\fR method:
.PP
.Vb 1
\& print header(-cookie=>$c);
.Ve
.PP
Mod_perl users can set cookies using the request object's \fIheader_out()\fR
method:
.PP
.Vb 1
\& $r->headers_out->set('Set-Cookie' => $c);
.Ve
.PP
Internally, Cookie overloads the "" operator to call its \fIas_string()\fR
method when incorporated into the \s-1HTTP\s0 header. \fIas_string()\fR turns the
Cookie's internal representation into an RFC-compliant text
representation. You may call \fIas_string()\fR yourself if you prefer:
.PP
.Vb 1
\& print "Set-Cookie: ",$c->as_string,"\en";
.Ve
.Sh "Recovering Previous Cookies"
.IX Subsection "Recovering Previous Cookies"
.Vb 1
\& %cookies = fetch CGI::Cookie;
.Ve
.PP
\&\fBfetch\fR returns an associative array consisting of all cookies
returned by the browser. The keys of the array are the cookie names. You
can iterate through the cookies this way:
.PP
.Vb 4
\& %cookies = fetch CGI::Cookie;
\& foreach (keys %cookies) {
\& do_something($cookies{$_});
\& }
.Ve
.PP
In a scalar context, \fIfetch()\fR returns a hash reference, which may be more
efficient if you are manipulating multiple cookies.
.PP
\&\s-1CGI\s0.pm uses the \s-1URL\s0 escaping methods to save and restore reserved characters
in its cookies. If you are trying to retrieve a cookie set by a foreign server,
this escaping method may trip you up. Use \fIraw_fetch()\fR instead, which has the
same semantics as \fIfetch()\fR, but performs no unescaping.
.PP
You may also retrieve cookies that were stored in some external
form using the \fIparse()\fR class method:
.PP
.Vb 2
\& $COOKIES = `cat /usr/tmp/Cookie_stash`;
\& %cookies = parse CGI::Cookie($COOKIES);
.Ve
.PP
If you are in a mod_perl environment, you can save some overhead by
passing the request object to \fIfetch()\fR like this:
.PP
.Vb 1
\& CGI::Cookie->fetch($r);
.Ve
.Sh "Manipulating Cookies"
.IX Subsection "Manipulating Cookies"
Cookie objects have a series of accessor methods to get and set cookie
attributes. Each accessor has a similar syntax. Called without
arguments, the accessor returns the current value of the attribute.
Called with an argument, the accessor changes the attribute and
returns its new value.
.IP "\fB\f(BIname()\fB\fR" 4
.IX Item "name()"
Get or set the cookie's name. Example:
.Sp
.Vb 2
\& $name = $c->name;
\& $new_name = $c->name('fred');
.Ve
.IP "\fB\f(BIvalue()\fB\fR" 4
.IX Item "value()"
Get or set the cookie's value. Example:
.Sp
.Vb 2
\& $value = $c->value;
\& @new_value = $c->value(['a','b','c','d']);
.Ve
.Sp
\&\fB\f(BIvalue()\fB\fR is context sensitive. In a list context it will return
the current value of the cookie as an array. In a scalar context it
will return the \fBfirst\fR value of a multivalued cookie.
.IP "\fB\f(BIdomain()\fB\fR" 4
.IX Item "domain()"
Get or set the cookie's domain.
.IP "\fB\f(BIpath()\fB\fR" 4
.IX Item "path()"
Get or set the cookie's path.
.IP "\fB\f(BIexpires()\fB\fR" 4
.IX Item "expires()"
Get or set the cookie's expiration time.
.SH "AUTHOR INFORMATION"
.IX Header "AUTHOR INFORMATION"
Copyright 1997\-1998, Lincoln D. Stein. All rights reserved.
.PP
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
.PP
Address bug reports and comments to: lstein@cshl.org
.SH "BUGS"
.IX Header "BUGS"
This section intentionally left blank.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
CGI::Carp, \s-1CGI\s0