Skip to content

Instantly share code, notes, and snippets.

@1stevengrant
Created May 24, 2014 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stevengrant/5ee4913109dd0922ed74 to your computer and use it in GitHub Desktop.
Save 1stevengrant/5ee4913109dd0922ed74 to your computer and use it in GitHub Desktop.
add this to your CMS index file to protect a file
if($_SERVER['SERVER_ADDR'] == '127.0.0.1') {
$username = 'username';
$password = 'password';
if (!(isset($_SERVER['PHP_AUTH_USER']) && ($_SERVER['PHP_AUTH_USER']==$username && $_SERVER['PHP_AUTH_PW']==$password))) {
header('WWW-Authenticate: Basic realm="This site is protected"');
header('HTTP/1.0 401 Unauthorized');
// Fallback message when the user presses cancel / escape
echo 'Access denied';
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment