Basic Authentication
Basic Authentication –
Authentication for protected websites
Introduction to Basic Authentication
Basic Authentication is a challenge-response mechanism described in RFC 2617.
How to use Basic Authentication
Basic Authentication
The following example assumes that one wants to fetch a page
/protected.html
on the host
example.com
that is protected using Basic
Authentication. The necessary username to pass the authentication is
johndoe
and the appendant password is
foo
.
<?php
require_once "HTTP/Request.php";
$req =& new HTTP_Request("http://example.com/protected.html");
$req->setBasicAuth("johndoe", "foo");
$response = $req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage();
} else {
echo $req->getResponseBody();
}
?>