【问题标题】:Warning: mysqli_connect(): (28000/1045): on Cpanel警告:mysqli_connect(): (28000/1045): 在 Cpanel
【发布时间】:2014-07-17 14:10:21
【问题描述】:

在 cPanel 上部署我的网站后,我遇到了这个问题。重要的一点是它可以在 localhost 和 amazon-EC2 服务器上完美运行。所以在你将此问题标记为重复之前,请彻底理解它。

我的功能是,当用户提交表单时,会在服务器上创建一个 php 文件,其中包含 sql 查询(计算对该文件的点击次数)和其他与功能相关的动态内容。但是当该文件在浏览器中执行时,它会给出警告

Warning: mysqli_connect(): (28000/1045): Access denied for user 'socialle_slcm'@'localhost' (using password: YES)` 

这个问题只发生在 cPanel 上。我检查了文件权限。但一切都好。请帮忙。

我的代码是

create.php(这会创建 user.php 文件)

<?php
    $txt = "
        <?php
           ob_start();
        ?>
        <html>
        <body>
        <?php
        ob_start();
        \$con=\mysqli_connect(\"localhost\",\"social\",\"sslc123\",\"socialle_slcm\");
        \$file_id = ".$file_id.";
        if (!empty(\$_SERVER['HTTP_CLIENT_IP'] ) ) {    
        \$ip = \$_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
        \$ip = \$_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
        \$ip = \$_SERVER['REMOTE_ADDR'];
        }
        \$date = \date('Y-m-d H:i:s');
        \$result = \mysqli_query(\$con,\"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '\$file_id' and ip_address = '\$ip'\");
        while(\$row = \mysqli_fetch_array(\$result))
        {
        \$count_ip = \$row['count_ip'];
        }
        if(\$count_ip == 0)
        {
        \$result = \mysqli_query(\$con,\"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('\$file_id','\$ip','\$date')\");
        }
        else
        {
        \$result = \mysqli_query(\$con,\"SELECT count FROM visitors where file_id = '$file_id' and  ip_address = '\$ip'\");
        while(\$row = \mysqli_fetch_array(\$result))
        {
        \$count = \$row['count'];
        }
        \$count++;

        \$result = mysqli_query(\$con,\"UPDATE visitors SET count = \$count,last_visited = '\$date' WHERE file_id = '\$file_id' and ip_address = '\$ip'\");
        }
        header('Location: ".$landing_page."');
        ?>
        </body>
        </html>
    ";
    fwrite($myfile, $txt);
    fclose($myfile); 

用户.php

<?php
ob_start();
?>
<html>
<body>
<?php
ob_start();
$con=\mysqli_connect("localhost","social","sslc123","socialle_slcm");
$file_id = 425;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$date = \date('Y-m-d H:i:s');
$result = \mysqli_query($con,"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '$file_id' and ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count_ip = $row['count_ip'];
}
if($count_ip == 0)
{
$result = \mysqli_query($con,"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('$file_id','$ip','$date')");
}
else
{
$result = \mysqli_query($con,"SELECT count FROM visitors where file_id = '425' and  ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count = $row['count'];
}
$count++;

$result = mysqli_query($con,"UPDATE visitors SET count = $count,last_visited = '$date' WHERE file_id = '$file_id' and ip_address = '$ip'");
}
header('Location: http://rackinfotech.com');
?>
</body>
</html>

这在 localhost 和 amazon-EC2 服务器上完美运行,并且仅在 cpanel 上出现问题。

【问题讨论】:

  • 希望这不是你的真实密码

标签: php mysql file cpanel


【解决方案1】:

您可以尝试使用服务器的 IP 地址,而不是使用localhost。此外,与使用 cPanel 的相比,您的 Amazon 服务器的 MySQL 版本是否不同?

【讨论】:

  • mysql版本没问题。因为网站中的其他查询正常工作。我会尝试使用服务器的 IP 地址。
【解决方案2】:

尤里卡!!!! 通过删除不必要的新行和html代码

解决了这个问题

因此创建的文件包含以下代码,并且可以完美运行。

<?php
ob_start();
$con=\mysqli_connect("localhost","social","sslc123","socialle_slcm");
$file_id = 425;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$date = \date('Y-m-d H:i:s');
$result = \mysqli_query($con,"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '$file_id' and ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count_ip = $row['count_ip'];
}
if($count_ip == 0)
{
$result = \mysqli_query($con,"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('$file_id','$ip','$date')");
}
else
{
$result = \mysqli_query($con,"SELECT count FROM visitors where file_id = '425' and  ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count = $row['count'];
}
$count++;

$result = mysqli_query($con,"UPDATE visitors SET count = $count,last_visited = '$date' WHERE file_id = '$file_id' and ip_address = '$ip'");
}
header('Location: http://rackinfotech.com');

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 2015-02-20
    • 2017-08-10
    • 2014-09-30
    • 2019-06-26
    • 2017-03-04
    相关资源
    最近更新 更多