flush
[mdref/mdref-http] / http / Client / Response / getCookies.md
1 # mixed http\Client\Response::getCookies([int $flags = 0[, array $allowed_extras = NULL]])
2
3 Extract response cookies.
4 Parses any "Set-Cookie" response headers into an http\Cookie list. See http\Cookie::__construct().
5
6 ## Params:
7
8 * Optional int $flags = 0
9 Cookie parser flags.
10 * Optional array $allowed_extras = NULL
11 List of keys treated as extras.
12
13 ## Returns:
14
15 * array, list of http\Cookie instances.
16
17
18 ## Example:
19
20 <?php
21 $response = (new http\Client)
22 ->enqueue(new http\Client\Request("GET", "http://php.net/"))
23 ->send()
24 ->getResponse();
25
26 foreach ($response->getCookies() as $cookie) {
27 /* @var $cookie http\Cookie */
28 foreach ($cookie->getCookies() as $name => $value) {
29 printf("Got a cookie named '%s' with value '%s'\n\tdomain=%s\n\t path=%s\n",
30 $name, $value, $cookie->getDomain(), $cookie->getPath());
31 }
32 }
33 ?>
34
35 Yields:
36
37 Got a cookie named 'COUNTRY' with value 'USA,72.52.91.14'
38 domain=.php.net
39 path=/