The Script Below cause a network username and password box to appare just a few things that are not happening and I can't get why.
if you put the wrong password one time you get to the page that you failed to access to page but if you back out it wont prompt you any more to try again.
You only get one chance instead of three
any reason why
Script:
<?
// Check to see if $PHP_AUTH_USER already
// contains info
if (!isset($PHP_AUTH_USER)) {
// if empty send header causing dialog box
// to appear
header('WWW-Authenticate: Basic realm="Protected Area"');
header('HTTP/1.0 401 Unauthroized');
echo 'Authentication Required.';
exit;
}
// if not empty grant access only if $PHP_AUTH_USER is Valid
else {
// Connect to the DB
// formulate the query
$sql = "SELECT user_name FROM user WHERE user_name='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";
// execute the query and put the results in $result
$result = mysql_query($sql) or die ("Couldn't get result");
// get number of row should be 0 if invalid 1 if valid
$num = mysql_numrows($result) or die ("Error");
// the script dies here if you fail to enter
// the correct username & passsword
// Present result based on validity
if ($num == 1) {
echo "<P>Welcome";
} else {
if ($num == 0) {
// on invalid should go here instead dies
// above
echo "You are not Authorized";
}
}
}
?>
Thanx in Advance
Richie TM