我只是从一本书,HeadFirst PHP和MySQL学习PHP和MySQL的基础知识,并且在其中一个教程中遇到了障碍。它是放入预设用户名和密码并访问页面的基本表单。但是,无论我是否输入正确或错误,它只会让我回到登录表单。在谷歌浏览器上它是一个完整的循环,在Safari上,它说尽管输入了正确的信息但我输错了信息。我还没有找到任何答案。
authorize.php代码位于
之下 <?php
// User name and password for authentication
$username = 'rock';
$password = 'roll';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
// The user name/password are incorrect so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Guitar Wars"');
exit('<h2>Guitar Wars</h2>Sorry, you must enter a valid user name and password to access this page.');
}
?>
引用它的admin.php页面如下:
<?php
require_once('authorize.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guitar Wars - High Scores Administration</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Guitar Wars - High Scores Administration</h2>
<p>Below is a list of all Guitar Wars high scores. Use this page to remove scores as needed.</p>
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Retrieve the score data
$query = "SELECT * FROM guitarwars ORDER BY score DESC, date ASC";
$data = mysqli_query($dbc, $query);
// Loop through the array of more data, formatting it as HTML
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
// Display the score data
echo '<tr class="scorerow"><td><strong>' . $row['name'] . '</strong></td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><a href="removescore.php?id=' . $row['id'] . '&date=' . $row['date'] .
'&name=' . $row['name'] . '&score=' . $row['score'] . '&screenshot=' . $row['screenshot'] .
'">Remove</a></td></tr>';
}
echo '</table>';
mysqli_close($dbc);
?>
</body>
</html>
我还在Fatcow网络服务器上托管这个,因为我只是一名学生,如果这有任何区别的话。
如果您发现错误,或者我只是使用过时的方法进行此类登录验证,请告诉我。这本书已有几年历史了,所以您可能会了解更多最新的学习资料。
编辑:我执行此操作的具体网址是maxwellantonucci.com/php_practice3/admin.php,适用于想直接查看的人
编辑2:更新以显示引用authorize.php的整个admin.php页面