0

我有一个脚本应该从我的网络服务器远程将我的 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);
?>

每次我从网络服务器运行它时,它都会超时。然后我的世界服务器崩溃了。

预期:“用户”已添加到白名单(来自本地主机)实际来自 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
4

1 回答 1

0

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

完成此操作后,您应该能够在网络服务器和 MC 数据库之间进行通信。

于 2013-02-19T00:52:28.553 回答