Minecraft RCON是';t在web服务器上运行时工作,但在localhost上工作


Minecraft RCON isn't working when ran from web server, but is working from localhost

我有一个脚本,应该从我的Web服务器远程将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工作)来自web服务器的实际值:

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

据我所知,当尝试连接到远程数据库时,必须首先允许远程机器连接。这是通过将远程计算机添加到PHPmyAdmin中的特权列表中来完成的,假设您正在运行mySQL的新ish版本。

一旦您完成了这项工作,那么您应该能够在Web服务器和MC数据库之间进行通信。