Example 42-1. Adding a cookie to the request
In this example a cookie named version is added to the HTTP request. The value of this cookie is the version string of the PHP interpreter that is running the instance of HTTP_Request.
require_once "HTTP/Request.php"; $req =& new HTTP_Request("http://example.com/"); $req->addCookie("version", phpversion()); $response = $req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage(); } else { echo $req->getResponseBody(); }
Example 42-2. Reading cookies from a HTTP response
Reading cookies that come with a HTTP response is shown in this following example.
require_once "HTTP/Request.php"; $req =& new HTTP_Request("http://example.com/"); $response = $req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage(); } else { print_r($req->getResponseCookies()); }