gpt4 book ai didi

php - 在 php 中使用身份验证连接到数据库时出错

转载 作者:行者123 更新时间:2023-11-29 22:22:36 24 4
gpt4 key购买 nike

错误是:

  1. Could not connect to MySQL: Access denied for user 'ZEBRAHEAD'@'localhost' (using password: YES)

    1. Warning: mysql_connect(): Access denied for user 'ZEBRAHEAD'@'localhost' (using password: YES) in C:\wamp\www\TestSite\authentication.php on line 12

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>

最佳答案

检查用户权限并授予权限

关于php - 在 php 中使用身份验证连接到数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30569938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com