I am still learning PHP and it's the first time I am using this library (TeamSpeak 3 PHP Framework), I am trying to return a count of online users in a specific group, I tried a few different ways and no success.
This one, counts all users in the group (including offline users):
$admins = 0;
foreach($ts3->serverGroupGetById(12)->clientList() as $client) {
$admins++;
}
So I tried to compare that list with the online users list:
$admins = 0;
foreach($ts3->serverGroupGetById(12)->clientList() as $client) {
if($ts3->clientList($client)) {
$admins++;
}
}
And it works sometimes, I say sometimes because I tried it on my virtual server and no issues, the count was right, but when I tried it on another virtual server (I changed the group ID and port) I get this:
Warning: preg_match(): Unknown modifier '9' in C:\xampp\htdocs\serverstatus\libraries\TeamSpeak3\Helper\String.php on line 192
That warning only shows up with some server groups, I don't know the reason.
$admins = 0;
foreach($ts3->clientList($client) as $client) {
$admins++;
}
I guess this piece of code should show all online users but I tested it and the value is not always the online users, like I said before on my virtual server it shows the right count but when I tried it on another virtual server I got 48 but there are 61 users online.
I know that was one year ago but that might help because I was Googling the same question and after some time I found out how to do it.
Here's what you are looking for, tested it and works:
Hope it will help ;)