使用Vatsimphp API生成多个在线用户

时间:2015-01-12 20:17:18

标签: php html api web

晚上好,

我已将以下PHP module实施到我的网络服务器上。

我还设置了一个cron作业,每5分钟刷新一次数据。

现在我想知道如何使用附带的API在我的主站点的首页上显示连接到VATSIM网络的用户数。

我不熟悉API,而且是一个PHP新手,所以我很感激你们给我的任何帮助。

给出的API示例是:

<?php

/*
 * This file is part of the Vatsimphp package
 *
 * Copyright 2013 - Jelle Vink <jelle.vink@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * Consult the documentation for more details at:
 * https://github.com/skymeyer/Vatsimphp/blob/master/docs/index.md
 */

use Vatsimphp\VatsimData;

require_once '../vendor/autoload.php';

$vatsim = new VatsimData();
$vatsim->loadData();

// General vatsim statistics
$general = $vatsim->getGeneralInfo()->toArray();

// List all pilots
$pilots = $vatsim->getPilots()->toArray();

// List all controllers
$controllers = $vatsim->getControllers()->toArray();

// List all clients (pilots and controllers)
$clients = $vatsim->getClients()->toArray();

// List all servers
$servers = $vatsim->getServers()->toArray();

// List all voice servers
$voice = $vatsim->getVoiceServers()->toArray();

// List all prefile registrations
$prefile = $vatsim->getPrefile()->toArray();

// Search clients based on call sign
$aal = $vatsim->searchCallsign('AAL')->toArray();

// Search clients based on vatsim id
$user = $vatsim->searchVatsimId('1165529')->toArray();

// Get the METAR for KSFO
$ksfo = $vatsim->getMetar('KSFO');

先谢谢你的帮助......

1 个答案:

答案 0 :(得分:0)

解决方案如下:

.php文件:

<?php
require_once 'C:\Users\Administrator\Desktop\Vatsimphp\vendor\autoload.php';

$logFile ='C:\Users\Administrator\Desktop\Vatsimphp\vendor\skymeyer\vatsimphp\app\logsusers.log';

$vatsim = new \Vatsimphp\VatsimData();
$vatsim->setConfig('cacheOnly', true);
$vatsim->setConfig('logFile', $logFile);

   if ($vatsim->loadData()) {
   $info = $vatsim->getGeneralInfo()->toArray();
}

?>

<?php
   echo "<style=\"color: white;\">Total Users Online: <b>{$info['connected_clients']}</b>.";
 ?>

JavaScript的:

<script type="text/javascript">
    function get_vatsim() {
        $.ajax({
            type: 'POST',
            url: '/online.php',
            data: {
                request: 'true'
            },
            success: function(reply) {
                $('.vatsim').html("" + reply + "");
            }
        });
    }
    $(document).ready(function() {
  get_vatsim();
});
</script>

HTML:

<div class="vatsim"></div>