Home » Authentication » Auth_HTTP » Manual
Provides a framework for user authentication (aka an "User-Login") based on the HTTP
Introduction
Introduction – to HTTP based authentication
Instead of generating an HTML driven form like PEAR::Auth does, this class sends header commands to the clients which cause them to present a login box like they are e.g. used in Apache's .htaccess mechanism.
Starting with Auth_HTTP 2.1.0, HTTP Digest Authentication (RFC2617) is experimentally supported.
Auth_HTTP::Auth_HTTP()
Auth_HTTP::Auth_HTTP() – constructor
Synopsis
void Auth_HTTP::Auth_HTTP (
string
$storageDriver = "DB"
, mixed
$options = ""
)
Description
Constructor for the authentication system
Parameter
-
string
$storageDriver -
name of the storage driver that should be used
-
mixed
$options -
a string containing some login information or an array containing a bunch of options for the storage driver
Note
This function can not be called statically.
Example
Using different DB parameters
<?php
require_once "Auth/HTTP.php";
$a = new Auth_HTTP("DB", "mysql://test:test@localhost/test");
$a->start();
?>
Auth_HTTP Example
Auth_HTTP Example – Example: A simple password protected page
Example
<?php
// example of Auth_HTTP basic implementation
require_once("Auth/HTTP.php");
// setting the database connection options
$AuthOptions = array(
'dsn'=>"pgsql://test:test@localhost/testdb",
'table'=>"testable", // your table name
'usernamecol'=>"username", // the table username column
'passwordcol'=>"password", // the table password column
'cryptType'=>"none", // password encryption type in your db
);
$a = new Auth_HTTP("DB", $AuthOptions);
$a->setRealm('yourrealm'); // realm name
$a->setCancelText('<h2>Error 401</h2>'); // error message if authentication fails
$a->start(); // starting the authentication process
if($a->getAuth()) // checking for autenticated user
{
echo "Hello $a->username welcome to my secret page";
};
?>
Auth_HTTP Example 2
Auth_HTTP Example 2 – Example: A password protected page with multiple rows fetch and md5 password
Example
<?php
// example of Auth_HTTP implementation with encrypted password and multiple columns fetch
require_once("Auth/HTTP.php");
// setting the database connection options
$AuthOptions = array(
'dsn'=>"pgsql://test:test@localhost/testdb",
'table'=>"testable", // your table name
'usernamecol'=>"username", // the table username column
'passwordcol'=>"password", // the table password column
'cryptType'=>"md5", // password encryption type in your db
'db_fields'=>"*", // enabling fetch for other db columns
);
$a = new Auth_HTTP("DB", $AuthOptions);
$a->setRealm('yourrealm'); // realm name
$a->setCancelText('<h2>Error 401</h2>'); // error message if authentication fails
$a->start(); // starting the authentication process
if($a->getAuth()) // checking for autenticated user
{
echo "Hello $a->username welcome to my secret page <BR>";
echo "Your details on file are: <BR>";
echo $a->getAuthData('userid'); // retriving other details from the database row
echo $a->getAuthData('telephone'); // in this example the user id, telephone number
echo $a->getAuthData('email'); // and email address
};
?>
Auth_HTTP::getAuth()
Auth_HTTP::getAuth() – check for an authenticated user
Synopsis
boolean Auth_HTTP::getAuth (
)
Description
Check if the user has been authenticated.
Return value
boolean -
If the user has already been authenticated, the function returns
TRUE. Otherwise it returns FALSE.
Note
This function can not be called statically.
Auth_HTTP::getStatus()
Auth_HTTP::getStatus() – returns informations about the current authentication status
Synopsis
string Auth_HTTP::getStatus (
)
Description
This function returns the current status of PEAR::Auth. The return values are constants that are defined by PEAR Auth.
Return value
string - possible values are
AUTH_IDLED, AUTH_EXPIRED,
AUTH_EXPIRED
Note
This function can not be called statically.
See
Auth_HTTP::start()
Auth_HTTP::start() – start authentication
Synopsis
void Auth_HTTP::start (
)
Description
Start the authentication process.
Note
This function can not be called statically.