previousBasic Authentication (Previous) (Next) File uploadsnext

View this page in Last updated: Tue, 02 Jun 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

Cookies

Cookies – Making use of Cookies within HTTP_Request.

How to add Cookie to a HTTP request

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.

<?php
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();
}
?>

Reading cookies from a HTTP response

Reading cookies that come with a HTTP response is shown in this following example.

<?php
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());
}
?>
previousBasic Authentication (Previous) (Next) File uploadsnext

Download Documentation Last updated: Tue, 02 Jun 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.