PHP code example of mikechip / php-httpauth

1. Go to this page and download the library: Download mikechip/php-httpauth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mikechip / php-httpauth example snippets


     
    $auth = new Mike4ip\HttpAuth();
    $auth->addLogin('admin', 'test');
    $auth->addLogin('foo', 'bar');
    $auth->

      /*
     * 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);
    })->