2.2.0
[mdref/mdref-http] / http / Env / Response / setCookie.md
1 # http\Env\Response http\Env\Response::setCookie(mixed $cookie)
2
3 Add cookies to the response to send.
4
5 ## Params:
6
7 * mixed $cookie
8 The cookie to send.
9
10 ## Returns:
11
12 * http\Env\Response, self.
13
14 ## Throws:
15
16 * http\Exception\InvalidArgumentException
17 * http\Exception\UnexpectedValueException
18
19 ## Example:
20
21 <?php
22
23 $r = new http\Env\Response;
24 $r->setCookie("visit=true; path=/");
25 $r->send(STDOUT);
26
27 ?>
28
29 Yields:
30
31 HTTP/1.1 200 OK
32 Set-Cookie: visit=true; path=/;
33 ETag: ""
34
35 ### Another example:
36
37 <?php
38
39 $c = new http\Cookie;
40 $c->addCookie("foo", "bar");
41 $c->setMaxAge(360);
42 $c->setDomain(".example.org");
43 $c->setPath("/");
44 $c->setFlags(http\Cookie::SECURE | http\Cookie::HTTPONLY);
45
46 $r = new http\Env\Response;
47 $r->setCookie($c);
48 $r->send(STDOUT);
49
50 ?>
51
52 Yields:
53
54 HTTP/1.1 200 OK
55 Set-Cookie: foo=bar; domain=.example.org; path=/; max-age=360; secure; httpOnly;
56 ETag: ""