Skip to content

Instantly share code, notes, and snippets.

@SiddheshNan
Created April 16, 2020 05:11
Show Gist options
  • Save SiddheshNan/dbda4f3326a398c525694fedc7926603 to your computer and use it in GitHub Desktop.
Save SiddheshNan/dbda4f3326a398c525694fedc7926603 to your computer and use it in GitHub Desktop.
<?php
error_reporting(0);
session_start();
$valid_passwords = array ("user" => "pass");
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$valid_users = array_keys($valid_passwords);
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
header('WWW-Authenticate: Basic realm="Please Enter Your Credentials"');
header('HTTP/1.0 401 Unauthorized');
session_destroy();
die ("Not Authorized");
}
else
{
echo "logged in!";
//other logic here..
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment