Skip to content

Instantly share code, notes, and snippets.

@javierjara
Created March 15, 2018 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javierjara/c9e47d91588f0c012ab92a9e8b07b7bb to your computer and use it in GitHub Desktop.
Save javierjara/c9e47d91588f0c012ab92a9e8b07b7bb to your computer and use it in GitHub Desktop.
//----------------------------------------------------------------------
// AUTENTICAZIONE
//----------------------------------------------------------------------
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$nobasic = substr($_SERVER['HTTP_AUTHORIZATION'], 6); // removing 'Basic ' from the string
$decoded = base64_decode($nobasic); // decoding string with user:password
list($client_user, $client_pass) = explode(':', $decoded);
if ($client_user == "hearst" && $client_pass == "hearst12") {
// Successfully authenticated
} else {
// Authentication failed, username or password are wrong
header('WWW-Authenticate: Basic realm="site"');
header('HTTP/1.0 401 Unauthorized');
echo "Wrong credentials :-(";
exit;
}
} else {
// Not authenticated as there is no appropriate header in HTTP request
header('WWW-Authenticate: Basic realm="site"');
header('HTTP/1.0 401 Unauthorized');
echo "Wrong credentials :-(";
exit;
}
//----------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment