【发布时间】: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 上出现问题。
【问题讨论】:
-
希望这不是你的真实密码