This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# HTTP Auth Wrapper | ||
Library provides simple HTTP authentication | ||
|
||
# Installation | ||
Just download and include classes from `src` or | ||
use Composer: | ||
|
||
`composer require mikechip/php-httpauth` | ||
|
||
# Sample use | ||
```php | ||
require_once('vendor/autoload.php'); | ||
|
||
$auth = new Mike4ip\HttpAuth(); | ||
$auth->addLogin('admin', 'test'); | ||
$auth->addLogin('foo', 'bar'); | ||
$auth->requireAuth(); | ||
|
||
print('This is your hidden page'); | ||
``` | ||
|
||
# Customization | ||
```php | ||
require_once('vendor/autoload.php'); | ||
|
||
/* | ||
* HTTP Auth with customization | ||
*/ | ||
$auth = new Mike4ip\HttpAuth(); | ||
$auth->setRealm('Pass login and password'); | ||
|
||
// Set unauthorized callback | ||
$auth->onUnauthorized(function() { | ||
print("<h1>403 Forbidden</h1>"); | ||
die; | ||
})->setCheckFunction(function($user, $pwd) { | ||
// List of logins => passwords | ||
$users = [ | ||
'admin' => 'test', | ||
'foo' => 'bar' | ||
]; | ||
|
||
// Returns true if login and password matches | ||
return (isset($users[$user]) && $users[$user] === $pwd); | ||
})->requireAuth(); | ||
|
||
print('This is your hidden page'); | ||
``` | ||
|
||
# Feedback | ||
Use **Issues** to contact me |