Page 1 of 1

i have a challenge

Posted: Fri Jul 04, 2014 3:18 pm
by toyo
Im looking to use PhP to connect to virtual server (Teamspeak) and issue a command. Would anyone have the knowledge to help me?

This is an example that i found (Couldnt get it to work

Code: Select all

<?PHP
/**
  * serverlist.php
  *
  * Is a small script to demonstrate how to get a serverlist via ts3admin.class
  *
  * by par0noid solutions - ts3admin.info
  *
*/

/*-------SETTINGS-------*/
$ts3_ip = '173.74.170.196';
$ts3_queryport = 10011;
$ts3_user = 'wpcom';
$ts3_pass = '1eRz36XS';
/*----------------------*/

#Include ts3admin.class.php
require("ts3admin.class.php");

#build a new ts3admin object
$tsAdmin = new ts3admin($ts3_ip, $ts3_queryport);

if($tsAdmin->getElement('success', $tsAdmin->connect())) {
	#login as serveradmin
	$tsAdmin->login($ts3_user, $ts3_pass);
	
	#get serverlist
	$servers = $tsAdmin->"use 1"();
	$servers = $tsAdmin->clientlist();
	
	#set output var
	$output = '';
	
	#generate table codes for all servers
	foreach($servers['data'] as $server) {
		$output .= '<tr bgcolor="#ffffff" onmouseover="style.backgroundColor=\'#eeeeee\'" onmouseout="style.backgroundColor=\'#ffffff\'">';
		$output .= '<td width="50px" align="center">#'.$server['virtualserver_id'].'</td>';
		$output .= '<td width="300px">&nbsp;&nbsp;'.htmlspecialchars($server['virtualserver_name']).'</td>';
		$output .= '<td width="100px" align="center">'.$server['virtualserver_port'].'</td>';
		if(isset($server['virtualserver_clientsonline'])) {
			$clients = $server['virtualserver_clientsonline'] . '/' . $server['virtualserver_maxclients'];
		}else{
			$clients = '-';
		}
		$output .= '<td width="200px" align="center">'.$clients.'</td>';
		$output .= '<td width="100px" align="center">'.$server['virtualserver_status'].'</td>';
		if(isset($server['virtualserver_uptime'])) {
			$uptime = $tsAdmin->convertSecondsToStrTime(($server['virtualserver_uptime']));
		}else{
			$uptime = '-';
		}
		$output .= '<td width="150px" align="center">'.$uptime.'</td>';
	}
}else{
	echo 'Connection could not be established.';
}

if(count($tsAdmin->getDebugLog()) > 0) {
	foreach($tsAdmin->getDebugLog() as $logEntry) {
		echo '<script>alert("'.$logEntry.'");</script>';
	}
}

?>
<html>
	<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Serverlist example by Par0noid Solutions</title>
        <style>
			* {
				font-size:13px;
				font-family:Verdana, Geneva, sans-serif;
			}
		</style>
    </head>
    <body bgcolor="#a2ad9b">
    	<table bgcolor="#000000" cellpadding="5" cellspacing="1" width="900px" border="0" align="center">
        	<tr bgcolor="#c0c0c0">
            	<td width="50px" align="center"><b>ID<b></td>
                <td width="300px" align="center"><b>Servername<b></td>
            	<td width="100px" align="center"><b>Port<b></td>
            	<td width="200px" align="center"><b>Current clients<b></td>
                <td width="100px" align="center"><b>Status<b></td>
                <td width="150px" align="center"><b>Uptime<b></td>
            </tr>
            <?PHP echo $output; ?>
        </table>
    </body>
</html>

Re: i have a challenge

Posted: Fri Jul 04, 2014 6:35 pm
by requinix
"Couldn't get it to work" doesn't help much. How is it not working? What is it doing and what is it supposed to do?

Re: i have a challenge

Posted: Fri Jul 04, 2014 7:37 pm
by Celauran
Posting the contents of the included class would also be helpful.

Re: i have a challenge

Posted: Sat Jul 05, 2014 3:50 pm
by toyo
OK. thx for your quick reply guys.... That code is suppose to connect to the Teamspeak servers Server Query, run a log in command, as well as a couple others to retrieve the client list. It should return the client list back to the webpage for you to see. But, i can never get it to connect to the Query.

Re: i have a challenge

Posted: Mon Jul 07, 2014 9:02 am
by toyo
i really dont knw whats wrong with this code.............

Re: i have a challenge

Posted: Mon Jul 07, 2014 9:18 am
by Celauran
Celauran wrote:Posting the contents of the included class would also be helpful.

Re: i have a challenge

Posted: Mon Jul 07, 2014 9:31 am
by toyo
tried posnting it but it was too long and the file aint attatching

Re: i have a challenge

Posted: Mon Jul 07, 2014 9:33 am
by Celauran
If it's hosted on GitHub or BitBucket, you could link to it there. Alternately, you could use a service like pastebin. As it stands now, we've got a black box class that's "not working". We've got nothing to work with.