-
-
Save javierjara/c9e47d91588f0c012ab92a9e8b07b7bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------------------------------------------------------------------- | |
// 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