Skip to content

Instantly share code, notes, and snippets.

@jayde
Created July 4, 2013 16:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jayde/5928967 to your computer and use it in GitHub Desktop.
Save jayde/5928967 to your computer and use it in GitHub Desktop.
PHP Basic Site Authentication / Password Protect
<?
header("Content-type: text/html; charset=utf-8");
if(empty($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized');
echo 'Login and Password Required';
exit;
} else {
echo "Username: ".$_SERVER['PHP_AUTH_USER']."<br>";
echo "Password: ".$_SERVER['PHP_AUTH_PW']."<p>";
$username = "login";
$password = "password";
if(($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized');
echo 'Login and Password Required';
exit;
} else {
echo "<title>".(isset($title)?$title:"DX1")."</title>\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment