Skip to content

Instantly share code, notes, and snippets.

@acacha
Last active Nov 17, 2016
Embed
What would you like to do?
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