This repository was archived by the owner on Jun 21, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ # HTTP Auth Wrapper
2+ Library provides simple HTTP authentication
3+
4+ # Installation
5+ Just download and include classes from ` src ` or
6+ use Composer:
7+
8+ ` composer require mikechip/php-httpauth `
9+
10+ # Sample use
11+ ``` php
12+ require_once('vendor/autoload.php');
13+
14+ $auth = new Mike4ip\HttpAuth();
15+ $auth->addLogin('admin', 'test');
16+ $auth->addLogin('foo', 'bar');
17+ $auth->requireAuth();
18+
19+ print('This is your hidden page');
20+ ```
21+
22+ # Customization
23+ ``` php
24+ require_once('vendor/autoload.php');
25+
26+ /*
27+ * HTTP Auth with customization
28+ */
29+ $auth = new Mike4ip\HttpAuth();
30+ $auth->setRealm('Pass login and password');
31+
32+ // Set unauthorized callback
33+ $auth->onUnauthorized(function() {
34+ print("<h1 >403 Forbidden</h1 >");
35+ die;
36+ })->setCheckFunction(function($user, $pwd) {
37+ // List of logins => passwords
38+ $users = [
39+ 'admin' => 'test',
40+ 'foo' => 'bar'
41+ ];
42+
43+ // Returns true if login and password matches
44+ return (isset($users[$user]) && $users[$user] === $pwd);
45+ })->requireAuth();
46+
47+ print('This is your hidden page');
48+ ```
49+
50+ # Feedback
51+ Use ** Issues** to contact me
You can’t perform that action at this time.
0 commit comments