Created
July 4, 2013 16:32
-
-
Save jayde/5928967 to your computer and use it in GitHub Desktop.
PHP Basic Site Authentication / Password Protect
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
<? | |
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