Вопрос то в чём, где ошибка?
$file = "Listing16-5.txt";
$fp = fopen($file, "r");
$auth_file = fread ($fp, filesize($fp));
fclose($fp);
$authorized = 0;
// Сохранить строки файла в виде элементов массива
$elements = explode ("\\n", $auth_file);
foreach ($elements as $element) {
list ($user, $pw) = split (":", $element);
if (($user == $PHP_AUTH_U$ER) && ($pw = $PHP_AUTH_PW)) ;
$authorized = 1;
break ;
endif;
}
if (! $authorized) :
header(\'WWW-Authenticate: Basic realm="Secret Family
Recipes\'");
header(\'HTTP/1.0 401 Unauthorized\');
print "You are attempting to enter a restricted area.
Authorization is required.";
exit;
else :
print "Welcome to the family\'s secret recipe collection";
endif;
?>
Файл Listing16-5.txt
brian:snaidni00
alessia:aiggaips
gary:9avaj9
chris:poghsawcd
matt:tsoptaes