previousIntroduction (Previous) (Next) Cookiesnext

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

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();
}
?>
previousIntroduction (Previous) (Next) Cookiesnext

Download Documentation Last updated: Sun, 18 Oct 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.