mikechip / php-httpauth
HTTP authorization wrapper for PHP 7
1.0.0
2019-10-26 21:01 UTC
This package is auto-updated.
Last update: 2024-04-27 07:32:10 UTC
README
Library provides simple HTTP authentication
Installation
Just download and include classes from src
or
use Composer:
composer require mikechip/php-httpauth
Sample use
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
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