PDA

View Full Version : User count script - I need a bug fix!


adamscybot
21-05-2006, 11:07
First, I didnt post in the original post for this script because its slowly died out and this question is a bit more generic.

I have the 'User count' script from this post (made by DarkCyrus):

http://forum.goteamspeak.com/showthread.php?t=30059

Here is the code for reference:

<?php
require("cyts.class.php");
$ts = new cyts;

//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$ts->connect("MY IP", MY QUERY PORT, MY PORT) or die ("Unable to connect to TeamSpeak - refresh");

$srvinfo = $ts->info_serverInfo();
echo '<img src="images/online.gif" align="top">&nbsp;&nbsp;' . '<b>' . $srvinfo["server_currentusers"] . " user(s) online" . '</b>';
?>

Obviously on the real thing all the ip's and ports are filled in.

The script works fine but there is one problem. I am using the script with an include so I can include it on my homepage. However, when the teamspeak goes down the whole website goes down because of the nature of this code.

When it is down the 'die' command is issued and in turn the whole webpage stops loading. I dont want this to happen, I just want the webpage to load fine but instead of showing how many users are online - it just says the TS is offline.

I heard this is possible with the 'return' command - but I dont know how to go about using it!

Help please!

Adam

Cyrus
21-05-2006, 11:15
<?php
require("cyts.class.php");
$ts = new cyts;

//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$ts->connect("MY IP", MY QUERY PORT, MY PORT) or die ("Unable to connect to TeamSpeak - refresh");

$srvinfo = $ts->info_serverInfo();
echo '<img src="images/online.gif" align="top">&nbsp;&nbsp;' . '<b>' . $srvinfo["server_currentusers"] . " user(s) online" . '</b>';
?>


<?php
require("cyts.class.php");
$ts = new cyts;

//Parameters are: IP-Address, TCP-Queryport, UDP-Port
if ($ts->connect("MY IP", MY QUERY PORT, MY PORT)) {

$srvinfo = $ts->info_serverInfo();
echo '<img src="images/online.gif" align="top">&nbsp;&nbsp;' . '<b>' . $srvinfo["server_currentusers"] . " user(s) online" . '</b>';
} else {
echo 'The server is offline!';
}
?>

adamscybot
21-05-2006, 11:53
Very quick!

It worked like a charm!

Thanks again,
Adam