I created a user-defined tag called password_protect and added the following code:
Code: Select all
function call_http_authentication() {
header('WWW-Authenticate: Basic realm="Enter username and password"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorisation Failed. Refresh page to try again.';
exit;
}
function call_to_authenticate($params) {
if(isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] == $params['username'] && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] == $params['password']) {}
else
call_http_authentication();
}
call_to_authenticate($params);
Code: Select all
{password_protect username="hello" password="you"}