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();
}
?>
Introduction to HTTP_Request (Previous) Making use of Cookies within HTTP_Request. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.