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");
}

?>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to