0

我有一个大问题,因为当我试图显示我的 ts3 服务器的状态时,我有空白页......我做错了什么?

require_once('libraries/TeamSpeak3/TeamSpeak3.php');
try
        {
          // connect to server, authenticate and grab info
          $ts3 = TeamSpeak3::factory("serverquery://query_admin:query_pass@host:10011/?server_port=9987");

          // show server as online
            $serverinfo[$j]['hostname'] = $ts3->virtualserver_name;
            $serverinfo[$j]['online'] = 'online';
            $serverinfo[$j]['players'] = $ts3->virtualserver_clientsonline;
            $serverinfo[$j]['max'] = $ts3->virtualserver_maxclients;

        }
        catch(Exception $e)
        {
          // grab errors and show server as offline
            $serverinfo[$j]['online'] = 'offline';
            $serverinfo[$j]['players'] = '-';
            $serverinfo[$j]['max'] = '-';
        }

当我评论此代码时,页面显示正常...

编辑:我现在看到了,如果我只添加这个 require_once('libraries/TeamSpeak3/TeamSpeak3.php'); 仅此而已,我的代码显示空白页...是否有可能,此处的该库无法正常工作?

4

1 回答 1

0

您忘记在每个信息之前添加回声,因此代码变为:

require_once('libraries/TeamSpeak3/TeamSpeak3.php');
try
    {
      // connect to server, authenticate and grab info
      $ts3 = TeamSpeak3::factory("serverquery://query_admin:query_pass@host:10011/?server_port=9987");

      // show server as online
        echo $serverinfo[$j]['hostname'] = $ts3->virtualserver_name;
        echo $serverinfo[$j]['online'] = 'online';
        echo $serverinfo[$j]['players'] = $ts3->virtualserver_clientsonline;
        echo $serverinfo[$j]['max'] = $ts3->virtualserver_maxclients;

    }
    catch(Exception $e)
    {
      // grab errors and show server as offline
        echo $serverinfo[$j]['online'] = 'offline';
        echo $serverinfo[$j]['players'] = '-';
        echo $serverinfo[$j]['max'] = '-';
    }
于 2018-08-09T16:58:02.027 回答