PHP code example of opb / slim-basic-auth

1. Go to this page and download the library: Download opb/slim-basic-auth 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/ */

    

opb / slim-basic-auth example snippets


// MyAuthClass - implementing the im\Middleware\AuthCheckerInterface
{
	// only function th system
		// do some stuff and return true if authorised, false if not	
	}
}

// the rest of your Slim app, adding in the middleware

$app = new \Slim\Slim();

$authChecker = new MyAuthCLass;

$app->add(new \Slim\Middleware\HttpBasicAuth($authChecker, array(
	'path' => '/api', // optional, defaults to '/'
	'realm' => 'Protected API' // optional, defaults to 'Protected Area'
)));