错误是:
- 醇>
无法连接到MySQL:用户'ZEBRAHEAD'@'localhost'拒绝访问(使用密码:是)
- 警告:mysql_connect():用户'ZEBRAHEAD'@'localhost'(使用密码:YES)拒绝访问 第12行的C:\ wamp \ www \ TestSite \ authentication.php
DB_USER正在使用计算机的名称。
authentication.php
<?php
$authorized = FALSE;
if ((isset($_SERVER['PHP_AUTH_USER']) AND isset($_SERVER['PHP_AUTH_PW'])))
{
define ('DB_USER','ZEBRAHEAD');
define ('DB_PASSWORD','password');
define ('DB_HOST','localhost');
define ('DB_NAME','registration');
$dbc = mysql_connect (DB_HOST,DB_USER,DB_PASSWORD) OR die ('Could not connect to MySQL: '.mysql_error());
mysql_select_db (DB_NAME) OR die ('Could not select the database: '.mysql_error());
$query ="SELECT first_name FROM users WHERE username='{$_SERVER['PHP_AUTH_USER']}' AND password=PASSWORD('{$_SERVER['PHP_AUTH_PW']}')";
$result = mysql_query($query);
$row=mysql_fetch_array ($result);
if ($row)
{
$authorized = TRUE;
}
}
if(!$authorized)
{
header('WWW-Authenticate: Basic realm="My WebSite"');
header ('HTTP/1.0 401 Unauthorized');
}
?>
的index.php
<?php
require_once('authentication.php');
?>
<html>
<head></head>
<body>
if ($authorized)
{
echo "<p>Please enter a valid username and password!</p>";
}
else
{
echo "<p>You have been authenticated!</p>";
}
?>
</body>
</html>
答案 0 :(得分:0)
检查用户的权限并给予特权
答案 1 :(得分:0)
拳头确保您使用的是正确的用户名。要检查所有用户,请执行以下查询:
SELECT User FROM mysql.user;
一旦确认您使用了上述查询结果中的正确用户名,请确保您的密码正确无误。
答案 2 :(得分:0)