我有一个脚本,应该从我的网络服务器远程将我的Minecraft服务器上的人列入白名单。
从我的本地主机运行时,此脚本运行正常,但在我的Web服务器上运行时(连接超时)则不行。有什么能够实现这一目标吗?
<?php
require('../private/config.php');
function connectDB($user, $pass, $db) {
try {
return(new PDO("mysql:host=localhost;dbname=" . $db . ";charset=utf8", $user, $pass));
} catch(PDOException $ex) {
return $ex;
}
}
$db = connectDB($dbUser, $dbPass, $dbName);
if ($db instanceof PDOException) {
die ($db->getMessage());
}
if(!isset($_GET['user']) || $_GET['user']=='') {
die('User undefined.');
}
if(!isset($_GET['pw']) || $_GET['pw']=='') {
die('Not Authorised.');
}
if($_GET['pw']!=$whitelistpassword) {
die('Not Authorised.');
}
$user = $_GET['user'];
define( 'MQ_SERVER_ADDR', '[ip]' );
define( 'MQ_SERVER_PORT', 25605 );
define( 'MQ_SERVER_PASS', 'passwordtest' );
define( 'MQ_TIMEOUT', 5 );
require 'MinecraftQuery/MinecraftRcon.class.php';
try
{
$Rcon = new MinecraftRcon;
$Rcon->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_SERVER_PASS, MQ_TIMEOUT );
$Data = $Rcon->Command("whitelist add ".$user);
if($Data===false) {
throw new MinecraftRconException("Failed to get command result.");
}
else if(StrLen($Data)==0) {
throw new MinecraftRconException("Got command result, but it's empty.");
}
//echo HTMLSpecialChars($Data);
}
catch( MinecraftRconException $e )
{
header('Location: approve.php?pw='.$whitelistpassword);
die('Error');
}
$Rcon->Disconnect();
$sql = "UPDATE `Applications` SET `Approved` = 1 WHERE `Minecraft` = :user";
$stmt = $db->prepare($sql);
$stmt->bindParam(':user', $user);
$stmt->execute();
header('Location: approve.php?pw='.$whitelistpassword);
?>
每次我从网络服务器运行它都会超时。然后Minecraft服务器崩溃了。
预期:“用户”已添加到白名单中(来自localhost) 来自网络服务器的实际内容:
Warning: fsockopen() [function.fsockopen]: unable to connect to [ip]:25605 (Connection timed out) in /home/dooog/public_html/MinecraftQuery/MinecraftRcon.class.php on line 38
Warning: Cannot modify header information - headers already sent by (output started at /home/dooog/public_html/MinecraftQuery/MinecraftRcon.class.php:38) in /home/dooog/public_html/whitelistsend.php on line 57
答案 0 :(得分:0)
据我所知,在尝试连接远程数据库时,必须首先允许远程计算机连接。这是通过将远程机器添加到PHPmyAdmin中的特权列表来完成的,假设您正在运行mySQL的新版本。
完成后,您应该能够在Web服务器和MC数据库之间进行通信。