If you want to display your server information (server viewer) on an external website, you need to communicate with through the OGP protocol, on the query port (UDP) of your server.
In this tutorial, we will see how to use a PHP library to query our Onset server (in real-time) and retrieve server information + the list of connected players.
PHP - OGP Client for Onset
The official PHP client for the OGP protocol was written for PHP 4. We have created a fork compatible with the latest versions of PHP.
Feel free to contribute on Github (https://github.com/mTxServ/php-open-game-protocol-client).
This library is easy to use in your PHP code to allow you to retrieve real-time information, useful by example, to create a Onset server viewer (included in our Onset Server Hosting offers).
First, include the OGP class in your project. To use it:
<?php
require_once 'ogp.php';
$ogp = new \OGP\OGP('127.0.0.1', 27015);
if(!$ogp->getStatus()) {
die("Error: ".$ogp->error);
}
var_dump(
$ogp->serverInfo,
$ogp->players,
$ogp->rules,
$ogp->teams,
$ogp->addons,
$ogp->limits,
$ogp->ping
);
127.0.0.1
The IP address of your Onset private server.27015
Query Port
of your server (default:port - 1
).