HTTP authentication script failure display
| From: | John Hughes | Date: | Thu, 04 Apr 2002 15:40:32 +0000 |
| Subject: | HTTP authentication script failure display | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-18203@lists.php.net to get a copy of this message | ||
I have adapted a HTTP authentication script from Leon Atkinson's Core PHP
book. I've done something that stopped the failure message from displaying.
The password request works and valid users are sent to the correct page. But
instead of getting "This directory requires a user name and password" when a
failure occurs, I get a blank screeen. I've compared the code in the book
with mine but I can't see what I've done. Any help would be appreciated.
John Hughes
<?
session_start();
/*
** Check password
*/
if($PHP_AUTH_USER != '')
{
require (**********/connect_***.***');
$sql = "
SELECT *
FROM users
WHERE username = '$PHP_AUTH_USER' AND password = password('$PHP_AUTH_PW')
";
$result = mysql_query($sql,$connection) or die ("Can't execute query.");
$num = mysql_numrows($result);
if ($num != 0) {
$valid="yes";
$user=$username;
session_register('valid');
session_register('user');
header("Location:letters.php");
exit;
} #end if
} ELSE { //SEND headers to request username and password
header("WWW-Authenticate: Basic realm='The Letters Realm'");
header("HTTP/1.0 401 Unauthorized");
//show failure text
print("This directory requires a user name and password.<br>\n");
}
?>