File: cookie-plugin.rst

package info (click to toggle)
php-guzzle 3.9.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,084 kB
  • ctags: 7,622
  • sloc: php: 31,344; xml: 176; makefile: 144; python: 45; sh: 5
file content (33 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
=============
Cookie plugin
=============

Some web services require a Cookie in order to maintain a session. The ``Guzzle\Plugin\Cookie\CookiePlugin`` will add
cookies to requests and parse cookies from responses using a CookieJar object:

.. code-block:: php

    use Guzzle\Http\Client;
    use Guzzle\Plugin\Cookie\CookiePlugin;
    use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;

    $cookiePlugin = new CookiePlugin(new ArrayCookieJar());

    // Add the cookie plugin to a client
    $client = new Client('http://www.test.com/');
    $client->addSubscriber($cookiePlugin);

    // Send the request with no cookies and parse the returned cookies
    $client->get('http://www.yahoo.com/')->send();

    // Send the request again, noticing that cookies are being sent
    $request = $client->get('http://www.yahoo.com/');
    $request->send();

    echo $request;

You can disable cookies per-request by setting the ``cookies.disable`` value to true on a request's params object.

.. code-block:: php

    $request->getParams()->set('cookies.disable', true);