I am currently using TeamSpeak's ServerQuery feature to display all channels and connected users via PHP on my website. Right now it looks like this: (apologies for the crude usernames/channel titles)
It works to display channels and user names. However, I do not want it to do this.
Instead of showing all channels and user names that have connected, I would prefer it just to fetch the amount of users that are currently connected and the maximum amount of users that can connect and display them as seen above. (Along with the server status, i.e online or offline.)
This is the API I am using to connect to the TeamSpeak server via PHP.
Discovered a solution by myself!
Framework
We only really need the libraries folder for this situation, so feel free to delete the docs and images folders.
--
PHP (Thanks to SilentStorm)
<?php
date_default_timezone_set("Europe/London");
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
TeamSpeak3::init();
header('Content-Type: text/html; charset=utf8');
$status = "offline";
$count = 0;
$max = 0;
try {
$ts3 = TeamSpeak3::factory("serverquery://<USER>:<PASSWORD>@<SERVER IP>:<QUERY PORT>/?server_port=<SERVER PORT>&use_offline_as_virtual=1&no_query_clients=1");
$status = $ts3->getProperty("virtualserver_status");
$count = $ts3->getProperty("virtualserver_clientsonline") - $ts3->getProperty("virtualserver_queryclientsonline");
$max = $ts3->getProperty("virtualserver_maxclients");
}
catch (Exception $e) {
echo '<div style="background-color:red; color:white; display:block; font-weight:bold;">QueryError: ' . $e->getCode() . ' ' . $e->getMessage() . '</div>';
}
echo '<span class="ts3status">TS3 Server Status: ' . $status . '</span><br/><span class="ts3_clientcount">Clients online: ' . $count . '/' . $max . '</span>';
?>
Customise
- ServerQuery username (Can be found in TeamSpeak, Tools -> ServerQuery Login
- ServerQuery password (Can be found in TeamSpeak, Tools -> ServerQuery Login
- The server's IP address
- The ServerQuery port (Default - 10011)
- The server's port (Default - 9987)
Save the file appropriately, in the same directory that includes the libraries folder. To display it on a page put the code:
<?php
include('path/to/file/filename.php');
?>
This will then display the TeamSpeak server information on the page! Hope I could help.