-1

我有一个安装脚本,它在本地主机上运行良好,但在共享主机上我总是得到“拒绝访问”,下面是安装脚本 mysql 代码。它真的很奇怪,它只在本地主机上本地工作。

if(isset($_POST['install'])) {
$AdminUsername = HtmlSpecialChars(strip_tags($_POST['admin_username']));
$AdminPassword = HtmlSpecialChars(strip_tags($_POST['admin_password']));
$dbhost = strip_tags($_POST['dbhost']);
$dbuser = strip_tags($_POST['dbuser']);
$dbpass = $_POST['dbpass'];
$sitename = strip_tags($_POST['sitename']);
$sql = "CREATE TABLE tickets
(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(32),
Email VARCHAR(40),
Subject VARCHAR(40),
Message TEXT(500),
open VARCHAR(10),
TimeCreated VARCHAR(40),
TimeUpdated VARCHAR(40),
hash VARCHAR(100)
)";
$sql2 = "CREATE TABLE config 
(
AdminUsername VARCHAR(32),
AdminPassword VARCHAR(32)
)";
$sql3 = "INSERT INTO config (AdminUsername,AdminPassword) VALUES ('$AdminUsername','$AdminPassword')";
 if(empty($dbhost)) {
echo "<div style='color:red;'>MySQL Database Host should not be empty!</div><br /><br />";
} elseif(empty($dbuser)) {
echo "<div style='color:red;'>MySQL Database User should not be empty!</div><br /><br />";
} elseif(empty($dbpass)) {
echo "<div style='color:red;'>MySQL Database Password should not be empty!</div><br /><br />"; 
} elseif(empty($sitename)) {
echo "<div style='color:red;'>Please enter a name for your new installation (It can be whatever you want)</div><br /><br />";
} elseif(empty($AdminUsername)) {
echo "<div style='color:red;'>Admin Username should not be empty!</div><br /><br />";
} elseif (empty($AdminPassword)) {
echo "<div style='color:red;'>Admin Password should not be empty!</div><br /><br />";
}
else {
$file = fopen('../configuration/config.php','r+');
fwrite($file, '<?php $dbhost = "'. $dbhost.'"; $dbuser = "'. $dbuser.'"; $dbpass = "'. $dbpass.'";  $sitename = "'. $sitename.'"; $temp = new mysqli ($dbhost, $dbuser, $dbpass);');
include('../configuration/config.php');
$temp->query("CREATE DATABASE tests");
$file2 = fopen('../configuration/config.php','r+');
fwrite($file2, '<?php $dbhost = "'. $dbhost.'"; $dbuser = "'. $dbuser.'"; $dbpass = "'. $dbpass.'";  $sitename = "'. $sitename.'"; $dbname = "tests"; $con = new mysqli ($dbhost, $dbuser, $dbpass,$dbname);');
include('../configuration/config.php');
fopen('install.lock','w');
header('Location: ../index.php');
}
}
}
} else {
echo "installation is locked";
}

我怎样才能使它在共享主机上工作?请,我真的很感激!在此先感谢我在stackoverflow上找不到答案,所以我决定将其发布为一个新问题

4

2 回答 2

0

它不会让您从共享托管环境中进入,但它会来自本地主机,这实际上并不奇怪。这就是 mysql 权限的工作方式,它们由用户和用户发出请求的 ip 定义。您的安装脚本将在 localhost 上运行,因为 'user'@'localhost' 具有创建和插入权限,但是看起来'user'@'sharedhostingip' 没有这些权限,因此您的请求得到满足带有拒绝访问的响应。如果您的用户有权修改用户,请尝试通过@您的服务器的 IP 地址向您的用户授予创建和插入权限,否则您将不得不联系您的 DBA 以添加这些权限。

希望这可以帮助。

于 2013-08-15T18:46:10.190 回答
0

您无权执行此操作。

如果用户无权创建数据库,则无法创建数据库。您要么必须为特定用户设置这些权限。如果他们首先阻止了这种情况,我怀疑共享主机会让你。

于 2013-08-15T18:42:07.153 回答