Skip to content

Instantly share code, notes, and snippets.

@acacha
Last active November 17, 2016 17:59
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 acacha/5ba1f028e40732c496b6d48bd81d092f to your computer and use it in GitHub Desktop.
Save acacha/5ba1f028e40732c496b6d48bd81d092f to your computer and use it in GitHub Desktop.
PHP HTTP Basic Authentication
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment