Skip to content

Instantly share code, notes, and snippets.

@alganet
Created June 15, 2013 16:42
Show Gist options
  • Save alganet/5788689 to your computer and use it in GitHub Desktop.
Save alganet/5788689 to your computer and use it in GitHub Desktop.
Auth Basic with Respect
{
"name": "respect/samples-auth-basic",
"authors": [
{
"name": "Alexandre Gaigalas",
"email": "alexandre@gaigalas.net"
}
],
"require": {
"respect/rest": "0.5.x"
}
}
<?php
require 'vendor/autoload.php';
use Respect\Rest\Router;
function checkLogin($user, $pass) {
// Replace with your own logic
return $user === 'admin' && $pass === 'my pass';
}
$r = new Router();
$r->get('/', function () {
return 'Home Public!';
});
$r->get('/admin', function () {
return 'Admin Protected!';
})->authBasic("Secret Area", function ($user, $pass) {
return checkLogin($user, $pass);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment