<?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>";
}
?>
Dear All,
Above is a code example from php.net
http://php.net/manual/en/features.http-auth.php
What I am left wondering is the SEQUENCE OF FLOW of logic here. Assume a
page has ONLY this code. Then the 1st time the if condition will branch into
if part ( and not the else ) . Then it will send a header and ask for a
username/password pair. When I enter that it is STILL in the IF part. How
will it jump to the else part and authorize me UNLESS when I press enter it
reloads the page. Maybe I am tired and not thinking straight. Would love to
hear a clarification on this.
Thank you,
Ashim