Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / CGI::Cookie.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "CGI::Cookie 3"
132.TH CGI::Cookie 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134CGI::Cookie \- Interface to Netscape Cookies
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& use CGI qw/:standard/;
139\& use CGI::Cookie;
140.Ve
141.PP
142.Vb 7
143\& # Create new cookies and send them
144\& $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
145\& $cookie2 = new CGI::Cookie(-name=>'preferences',
146\& -value=>{ font => Helvetica,
147\& size => 12 }
148\& );
149\& print header(-cookie=>[$cookie1,$cookie2]);
150.Ve
151.PP
152.Vb 3
153\& # fetch existing cookies
154\& %cookies = fetch CGI::Cookie;
155\& $id = $cookies{'ID'}->value;
156.Ve
157.PP
158.Vb 2
159\& # create cookies returned from an external source
160\& %cookies = parse CGI::Cookie($ENV{COOKIE});
161.Ve
162.SH "DESCRIPTION"
163.IX Header "DESCRIPTION"
164CGI::Cookie is an interface to Netscape (\s-1HTTP/1\s0.1) cookies, an
165innovation that allows Web servers to store persistent information on
166the browser's side of the connection. Although CGI::Cookie is
167intended to be used in conjunction with \s-1CGI\s0.pm (and is in fact used by
168it internally), you can use this module independently.
169.PP
170For full information on cookies see
171.PP
172.Vb 1
173\& http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt
174.Ve
175.SH "USING CGI::Cookie"
176.IX Header "USING CGI::Cookie"
177CGI::Cookie is object oriented. Each cookie object has a name and a
178value. The name is any scalar value. The value is any scalar or
179array value (associative arrays are also allowed). Cookies also have
180several optional attributes, including:
181.IP "\fB1. expiration date\fR" 4
182.IX Item "1. expiration date"
183The expiration date tells the browser how long to hang on to the
184cookie. If the cookie specifies an expiration date in the future, the
185browser will store the cookie information in a disk file and return it
186to the server every time the user reconnects (until the expiration
187date is reached). If the cookie species an expiration date in the
188past, the browser will remove the cookie from the disk file. If the
189expiration date is not specified, the cookie will persist only until
190the user quits the browser.
191.IP "\fB2. domain\fR" 4
192.IX Item "2. domain"
193This is a partial or complete domain name for which the cookie is
194valid. The browser will return the cookie to any host that matches
195the partial domain name. For example, if you specify a domain name
196of \*(L".capricorn.com\*(R", then Netscape will return the cookie to
197Web servers running on any of the machines \*(L"www.capricorn.com\*(R",
198\&\*(L"ftp.capricorn.com\*(R", \*(L"feckless.capricorn.com\*(R", etc. Domain names
199must contain at least two periods to prevent attempts to match
200on top level domains like \*(L".edu\*(R". If no domain is specified, then
201the browser will only return the cookie to servers on the host the
202cookie originated from.
203.IP "\fB3. path\fR" 4
204.IX Item "3. path"
205If you provide a cookie path attribute, the browser will check it
206against your script's \s-1URL\s0 before returning the cookie. For example,
207if you specify the path \*(L"/cgi\-bin\*(R", then the cookie will be returned
208to each of the scripts \*(L"/cgi\-bin/tally.pl\*(R", \*(L"/cgi\-bin/order.pl\*(R", and
209\&\*(L"/cgi\-bin/customer_service/complain.pl\*(R", but not to the script
210\&\*(L"/cgi\-private/site_admin.pl\*(R". By default, the path is set to \*(L"/\*(R", so
211that all scripts at your site will receive the cookie.
212.IP "\fB4. secure flag\fR" 4
213.IX Item "4. secure flag"
214If the \*(L"secure\*(R" attribute is set, the cookie will only be sent to your
215script if the \s-1CGI\s0 request is occurring on a secure channel, such as \s-1SSL\s0.
216.Sh "Creating New Cookies"
217.IX Subsection "Creating New Cookies"
218.Vb 7
219\& $c = new CGI::Cookie(-name => 'foo',
220\& -value => 'bar',
221\& -expires => '+3M',
222\& -domain => '.capricorn.com',
223\& -path => '/cgi-bin/database',
224\& -secure => 1
225\& );
226.Ve
227.PP
228Create cookies from scratch with the \fBnew\fR method. The \fB\-name\fR and
229\&\fB\-value\fR parameters are required. The name must be a scalar value.
230The value can be a scalar, an array reference, or a hash reference.
231(At some point in the future cookies will support one of the Perl
232object serialization protocols for full generality).
233.PP
234\&\fB\-expires\fR accepts any of the relative or absolute date formats
235recognized by \s-1CGI\s0.pm, for example \*(L"+3M\*(R" for three months in the
236future. See \s-1CGI\s0.pm's documentation for details.
237.PP
238\&\fB\-domain\fR points to a domain name or to a fully qualified host name.
239If not specified, the cookie will be returned only to the Web server
240that created it.
241.PP
242\&\fB\-path\fR points to a partial \s-1URL\s0 on the current server. The cookie
243will be returned to all URLs beginning with the specified path. If
244not specified, it defaults to '/', which returns the cookie to all
245pages at your site.
246.PP
247\&\fB\-secure\fR if set to a true value instructs the browser to return the
248cookie only when a cryptographic protocol is in use.
249.Sh "Sending the Cookie to the Browser"
250.IX Subsection "Sending the Cookie to the Browser"
251Within a \s-1CGI\s0 script you can send a cookie to the browser by creating
252one or more Set\-Cookie: fields in the \s-1HTTP\s0 header. Here is a typical
253sequence:
254.PP
255.Vb 3
256\& my $c = new CGI::Cookie(-name => 'foo',
257\& -value => ['bar','baz'],
258\& -expires => '+3M');
259.Ve
260.PP
261.Vb 2
262\& print "Set-Cookie: $c\en";
263\& print "Content-Type: text/html\en\en";
264.Ve
265.PP
266To send more than one cookie, create several Set\-Cookie: fields.
267.PP
268If you are using \s-1CGI\s0.pm, you send cookies by providing a \-cookie
269argument to the \fIheader()\fR method:
270.PP
271.Vb 1
272\& print header(-cookie=>$c);
273.Ve
274.PP
275Mod_perl users can set cookies using the request object's \fIheader_out()\fR
276method:
277.PP
278.Vb 1
279\& $r->headers_out->set('Set-Cookie' => $c);
280.Ve
281.PP
282Internally, Cookie overloads the "" operator to call its \fIas_string()\fR
283method when incorporated into the \s-1HTTP\s0 header. \fIas_string()\fR turns the
284Cookie's internal representation into an RFC-compliant text
285representation. You may call \fIas_string()\fR yourself if you prefer:
286.PP
287.Vb 1
288\& print "Set-Cookie: ",$c->as_string,"\en";
289.Ve
290.Sh "Recovering Previous Cookies"
291.IX Subsection "Recovering Previous Cookies"
292.Vb 1
293\& %cookies = fetch CGI::Cookie;
294.Ve
295.PP
296\&\fBfetch\fR returns an associative array consisting of all cookies
297returned by the browser. The keys of the array are the cookie names. You
298can iterate through the cookies this way:
299.PP
300.Vb 4
301\& %cookies = fetch CGI::Cookie;
302\& foreach (keys %cookies) {
303\& do_something($cookies{$_});
304\& }
305.Ve
306.PP
307In a scalar context, \fIfetch()\fR returns a hash reference, which may be more
308efficient if you are manipulating multiple cookies.
309.PP
310\&\s-1CGI\s0.pm uses the \s-1URL\s0 escaping methods to save and restore reserved characters
311in its cookies. If you are trying to retrieve a cookie set by a foreign server,
312this escaping method may trip you up. Use \fIraw_fetch()\fR instead, which has the
313same semantics as \fIfetch()\fR, but performs no unescaping.
314.PP
315You may also retrieve cookies that were stored in some external
316form using the \fIparse()\fR class method:
317.PP
318.Vb 2
319\& $COOKIES = `cat /usr/tmp/Cookie_stash`;
320\& %cookies = parse CGI::Cookie($COOKIES);
321.Ve
322.PP
323If you are in a mod_perl environment, you can save some overhead by
324passing the request object to \fIfetch()\fR like this:
325.PP
326.Vb 1
327\& CGI::Cookie->fetch($r);
328.Ve
329.Sh "Manipulating Cookies"
330.IX Subsection "Manipulating Cookies"
331Cookie objects have a series of accessor methods to get and set cookie
332attributes. Each accessor has a similar syntax. Called without
333arguments, the accessor returns the current value of the attribute.
334Called with an argument, the accessor changes the attribute and
335returns its new value.
336.IP "\fB\f(BIname()\fB\fR" 4
337.IX Item "name()"
338Get or set the cookie's name. Example:
339.Sp
340.Vb 2
341\& $name = $c->name;
342\& $new_name = $c->name('fred');
343.Ve
344.IP "\fB\f(BIvalue()\fB\fR" 4
345.IX Item "value()"
346Get or set the cookie's value. Example:
347.Sp
348.Vb 2
349\& $value = $c->value;
350\& @new_value = $c->value(['a','b','c','d']);
351.Ve
352.Sp
353\&\fB\f(BIvalue()\fB\fR is context sensitive. In a list context it will return
354the current value of the cookie as an array. In a scalar context it
355will return the \fBfirst\fR value of a multivalued cookie.
356.IP "\fB\f(BIdomain()\fB\fR" 4
357.IX Item "domain()"
358Get or set the cookie's domain.
359.IP "\fB\f(BIpath()\fB\fR" 4
360.IX Item "path()"
361Get or set the cookie's path.
362.IP "\fB\f(BIexpires()\fB\fR" 4
363.IX Item "expires()"
364Get or set the cookie's expiration time.
365.SH "AUTHOR INFORMATION"
366.IX Header "AUTHOR INFORMATION"
367Copyright 1997\-1998, Lincoln D. Stein. All rights reserved.
368.PP
369This library is free software; you can redistribute it and/or modify
370it under the same terms as Perl itself.
371.PP
372Address bug reports and comments to: lstein@cshl.org
373.SH "BUGS"
374.IX Header "BUGS"
375This section intentionally left blank.
376.SH "SEE ALSO"
377.IX Header "SEE ALSO"
378CGI::Carp, \s-1CGI\s0