Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Getting started

Stefan edited this page Oct 19, 2016 · 3 revisions

To start working with ts3admin.class is very simple. Create a php file next to the ts3admin.class.php. Open it and paste this to your file:

<?PHP
require('ts3admin.class.php');
?>

Now you're ready to go. Lets try to create an object of ts3admin.class like that:

<?PHP
require('ts3admin.class.php');

$ts3 = new ts3admin('127.0.0.1', 10011);
?>

127.0.0.1 is the IP of your Teamspeak server, 10011 is the default server query port, be sure that it's the same on yours.

Now lets connect:

<?PHP
require('ts3admin.class.php');

$ts3 = new ts3admin('127.0.0.1', 10011);

echo '<pre>'.print_r($ts3->connect(),true).'</pre>';
?>

The print_r command gives us the possibility to see what connect() returns, in my case an array with success, error and data. Success will contain a boolean, letting you know that your request was okay, error will contain occured errors during the command execution and data will contain requested data if you do so.

Please be sure that you added your webhost ip to the ts-server whitelist, otherwise you may get banned because of too much querys.

If you work with the PHP class you will sooner or later get errors because of misused function. To see what exactly the problem is, the getDebugLog() function was implemented. In the following example you can see how it should be used.

<?PHP
require('ts3admin.class.php');

$ts3 = new ts3admin('127.0.0.1', 10011);

echo '<pre>'.print_r($ts3->connect(),true).'</pre>';

/**
 * This code retuns all errors from the debugLog
 */
if(count($tsAdmin->getDebugLog()) > 0) {
	foreach($tsAdmin->getDebugLog() as $logEntry) {
		echo '<script>alert("'.$logEntry.'");</script>';
	}
}
?>

The getDebugLog function returns an array like this:

Array
{
 [0] => Error in login() on line 1908: ErrorID: 520 | Message: invalid loginname or password
 [1] => Error in selectServer() on line 2044: ErrorID: 1540 | Message: convert error
}
Clone this wiki locally