Skip to content

Instantly share code, notes, and snippets.

@drewgates
Forked from jayde/PHP Password Protect Website
Last active August 1, 2018 21:04
Show Gist options
  • Save drewgates/212ba79f156d3e92e8f433312c5fb892 to your computer and use it in GitHub Desktop.
Save drewgates/212ba79f156d3e92e8f433312c5fb892 to your computer and use it in GitHub Desktop.
PHP Simple Page 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 'Password Required';
exit;
} else {
$password = "password";
if(
($_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:"TITLE")."</title>\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment