Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

bssth/php-httpauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Auth Wrapper

Library provides simple HTTP authentication

Deprecated

The library was made quite a while ago and may be out of date. Please make a fork if you want to use it.

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy