Teamspeak 3 Framework

1.5k views Asked by At

I'm trying to get all clients database id, but I've been unable to using foreach etc as it always returns the value as NULL. I need to get a foreach with the database ids and put it in an array

$userchannel = $clients->cid->clientList["client_database_id"];
2

There are 2 answers

0
MAH3R On BEST ANSWER

I managed to fix it.

$ts3_VirtualServer->channelGetById(152) // 152 is the channel ID
3
BjornvanSchie On

After some fiddling i managed to get this to work, please verifiy. If you have questions regarding the code. Feel free to ask them.

What i've done in basic is modifing the existed code from the examples shown in the teamspeak php framework site. I used the Android user list for the most code. From there on its just trying and debugging ;)

this code will print the database id of the user together with the username. (Ofcourse from this point you can do everything you want with it.)

Also, maybe take a quick look at the api documentation for the php framework. It has alot of useful coding tips and tricks.

https://docs.planetteamspeak.com/ts3/php/framework/

edit (07-01-17) Something I also noticed, make sure the query user has enough rights, for ease I made mine server admin query (grants access to all options, Please be aware that this could be insecure in a active site!)

<?php
// load framework files
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

try {
  // connect to local server, authenticate and spawn an object for the virtual server on port 9988
  $ts3_ServerInstance = TeamSpeak3::factory("serverquery://###:##@####:##/?server_port=9987");
  $selected_sid = $ts3_ServerInstance->serverList();
  $ts3_VirtualServer = $ts3_ServerInstance->serverGetById($selected_sid);

  /* walk through list of clients */
  echo "<table class=\"list\">\n";
  echo "<tr>\n" .
       "  <th>DB id</th>\n" .
       "  <th>Nickname</th>\n" .
       "</tr>\n";
  foreach($ts3_VirtualServer->clientList() as $client) {
    echo "<tr>\n" .
         "  <td>" . $client['client_database_id'] . "</td>" .
         "  <td>" . htmlspecialchars($client) . "</td>" .
         "</tr>\n";
  }
  echo "</table>\n";
}
catch(Exception $e) {
  /* catch exceptions and display error message if anything went wrong */
  echo "<span class='error'><b>Error " . $e->getCode() . ":</b> " . $e->getMessage() . "</span>\n";
}