Commit | Line | Data |
---|---|---|
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" | |
134 | CGI::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" | |
164 | CGI::Cookie is an interface to Netscape (\s-1HTTP/1\s0.1) cookies, an | |
165 | innovation that allows Web servers to store persistent information on | |
166 | the browser's side of the connection. Although CGI::Cookie is | |
167 | intended to be used in conjunction with \s-1CGI\s0.pm (and is in fact used by | |
168 | it internally), you can use this module independently. | |
169 | .PP | |
170 | For 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" | |
177 | CGI::Cookie is object oriented. Each cookie object has a name and a | |
178 | value. The name is any scalar value. The value is any scalar or | |
179 | array value (associative arrays are also allowed). Cookies also have | |
180 | several optional attributes, including: | |
181 | .IP "\fB1. expiration date\fR" 4 | |
182 | .IX Item "1. expiration date" | |
183 | The expiration date tells the browser how long to hang on to the | |
184 | cookie. If the cookie specifies an expiration date in the future, the | |
185 | browser will store the cookie information in a disk file and return it | |
186 | to the server every time the user reconnects (until the expiration | |
187 | date is reached). If the cookie species an expiration date in the | |
188 | past, the browser will remove the cookie from the disk file. If the | |
189 | expiration date is not specified, the cookie will persist only until | |
190 | the user quits the browser. | |
191 | .IP "\fB2. domain\fR" 4 | |
192 | .IX Item "2. domain" | |
193 | This is a partial or complete domain name for which the cookie is | |
194 | valid. The browser will return the cookie to any host that matches | |
195 | the partial domain name. For example, if you specify a domain name | |
196 | of \*(L".capricorn.com\*(R", then Netscape will return the cookie to | |
197 | Web 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 | |
199 | must contain at least two periods to prevent attempts to match | |
200 | on top level domains like \*(L".edu\*(R". If no domain is specified, then | |
201 | the browser will only return the cookie to servers on the host the | |
202 | cookie originated from. | |
203 | .IP "\fB3. path\fR" 4 | |
204 | .IX Item "3. path" | |
205 | If you provide a cookie path attribute, the browser will check it | |
206 | against your script's \s-1URL\s0 before returning the cookie. For example, | |
207 | if you specify the path \*(L"/cgi\-bin\*(R", then the cookie will be returned | |
208 | to 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 | |
211 | that all scripts at your site will receive the cookie. | |
212 | .IP "\fB4. secure flag\fR" 4 | |
213 | .IX Item "4. secure flag" | |
214 | If the \*(L"secure\*(R" attribute is set, the cookie will only be sent to your | |
215 | script 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 | |
228 | Create 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. | |
230 | The 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 | |
232 | object serialization protocols for full generality). | |
233 | .PP | |
234 | \&\fB\-expires\fR accepts any of the relative or absolute date formats | |
235 | recognized by \s-1CGI\s0.pm, for example \*(L"+3M\*(R" for three months in the | |
236 | future. 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. | |
239 | If not specified, the cookie will be returned only to the Web server | |
240 | that created it. | |
241 | .PP | |
242 | \&\fB\-path\fR points to a partial \s-1URL\s0 on the current server. The cookie | |
243 | will be returned to all URLs beginning with the specified path. If | |
244 | not specified, it defaults to '/', which returns the cookie to all | |
245 | pages at your site. | |
246 | .PP | |
247 | \&\fB\-secure\fR if set to a true value instructs the browser to return the | |
248 | cookie 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" | |
251 | Within a \s-1CGI\s0 script you can send a cookie to the browser by creating | |
252 | one or more Set\-Cookie: fields in the \s-1HTTP\s0 header. Here is a typical | |
253 | sequence: | |
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 | |
266 | To send more than one cookie, create several Set\-Cookie: fields. | |
267 | .PP | |
268 | If you are using \s-1CGI\s0.pm, you send cookies by providing a \-cookie | |
269 | argument to the \fIheader()\fR method: | |
270 | .PP | |
271 | .Vb 1 | |
272 | \& print header(-cookie=>$c); | |
273 | .Ve | |
274 | .PP | |
275 | Mod_perl users can set cookies using the request object's \fIheader_out()\fR | |
276 | method: | |
277 | .PP | |
278 | .Vb 1 | |
279 | \& $r->headers_out->set('Set-Cookie' => $c); | |
280 | .Ve | |
281 | .PP | |
282 | Internally, Cookie overloads the "" operator to call its \fIas_string()\fR | |
283 | method when incorporated into the \s-1HTTP\s0 header. \fIas_string()\fR turns the | |
284 | Cookie's internal representation into an RFC-compliant text | |
285 | representation. 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 | |
297 | returned by the browser. The keys of the array are the cookie names. You | |
298 | can 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 | |
307 | In a scalar context, \fIfetch()\fR returns a hash reference, which may be more | |
308 | efficient 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 | |
311 | in its cookies. If you are trying to retrieve a cookie set by a foreign server, | |
312 | this escaping method may trip you up. Use \fIraw_fetch()\fR instead, which has the | |
313 | same semantics as \fIfetch()\fR, but performs no unescaping. | |
314 | .PP | |
315 | You may also retrieve cookies that were stored in some external | |
316 | form 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 | |
323 | If you are in a mod_perl environment, you can save some overhead by | |
324 | passing 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" | |
331 | Cookie objects have a series of accessor methods to get and set cookie | |
332 | attributes. Each accessor has a similar syntax. Called without | |
333 | arguments, the accessor returns the current value of the attribute. | |
334 | Called with an argument, the accessor changes the attribute and | |
335 | returns its new value. | |
336 | .IP "\fB\f(BIname()\fB\fR" 4 | |
337 | .IX Item "name()" | |
338 | Get 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()" | |
346 | Get 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 | |
354 | the current value of the cookie as an array. In a scalar context it | |
355 | will return the \fBfirst\fR value of a multivalued cookie. | |
356 | .IP "\fB\f(BIdomain()\fB\fR" 4 | |
357 | .IX Item "domain()" | |
358 | Get or set the cookie's domain. | |
359 | .IP "\fB\f(BIpath()\fB\fR" 4 | |
360 | .IX Item "path()" | |
361 | Get or set the cookie's path. | |
362 | .IP "\fB\f(BIexpires()\fB\fR" 4 | |
363 | .IX Item "expires()" | |
364 | Get or set the cookie's expiration time. | |
365 | .SH "AUTHOR INFORMATION" | |
366 | .IX Header "AUTHOR INFORMATION" | |
367 | Copyright 1997\-1998, Lincoln D. Stein. All rights reserved. | |
368 | .PP | |
369 | This library is free software; you can redistribute it and/or modify | |
370 | it under the same terms as Perl itself. | |
371 | .PP | |
372 | Address bug reports and comments to: lstein@cshl.org | |
373 | .SH "BUGS" | |
374 | .IX Header "BUGS" | |
375 | This section intentionally left blank. | |
376 | .SH "SEE ALSO" | |
377 | .IX Header "SEE ALSO" | |
378 | CGI::Carp, \s-1CGI\s0 |