0

I download a TS3AntiVPN but it shoes an error. I use a Linux Server running Debian 9 Plesk installed.

PHP Warning: Invalid argument supplied for foreach() in /var/www/vhosts/suspectgaming.de/tsweb.suspectgaming.de/antivpn/bot.php on line 29

How do I solve this problem?

<?php
require("ts3admin.class.php");
$ignore_groups = array('1',);   // now supports one input and array input 
$msg_kick = "VPN"; 
$login_query = "serveradmin"; 
$pass_query = ""; 
$adres_ip = "94.249.254.216";
$query_port = "10011"; 
$port_ts = "9987"; 
$nom_bot = "AntiVPN"; 

$ts = new ts3Admin($adres_ip, $query_port);

if(!$ts->getElement('success', $ts->connect()))  {
      die("Anti-Proxy");
}

$ts->login($login_query, $pass_query);
$ts->selectServer($port_ts);

$ts->setName($nom_bot);

while(true) {

    sleep(1);

    $clientList = $ts->clientList("-ip -groups");

    foreach($clientList['data'] as $val) {

        $groups = explode(",", $val['client_servergroups'] );

        if(is_array($ignore_groups)){

            foreach($ignore_groups as $ig){

                if(in_array($ig, $groups) || ($val['client_type'] == 1)) {

                    continue;   
                }
            }
        }else{

            if(in_array($ignore_groups, $groups) || ($val['client_type'] == 1)) {
                continue;
            }
        }

        $file = file_get_contents('https://api.xdefcon.com/proxy/check/?ip='.$val['connection_client_ip'].'');

        $file = json_decode($file, true);

        if($file['message'] == "Proxy detected.") {
            $ts->clientKick($val['clid'], "server", $msg_kick);
        }
    }
}

?>
Emma
  • 27,428
  • 11
  • 44
  • 69
kaitomar
  • 1
  • 2
  • 1
    Possible duplicate of [Invalid argument supplied for foreach()](https://stackoverflow.com/questions/2630013/invalid-argument-supplied-for-foreach) – Qirel Apr 28 '19 at 20:47

1 Answers1

0

You might be missing data in your first array. You may add an if statement to check if there is data in your $clientList['data'] var:

if (is_array($clientList['data'])) {


}

Or you might also check if sizeof(); of your array is larger than a number, you may desire.

if (is_array($clientList['data']) && sizeof($clientList['data']) > 0) {


}

Code

require "ts3admin.class.php";
$ignore_groups = array('1'); // now supports one input and array input
$msg_kick = "VPN";
$login_query = "serveradmin";
$pass_query = "";
$adres_ip = "94.249.254.216";
$query_port = "10011";
$port_ts = "9987";
$nom_bot = "AntiVPN";

$ts = new ts3Admin($adres_ip, $query_port);

if (!$ts->getElement('success', $ts->connect())) {
    die("Anti-Proxy");
}

$ts->login($login_query, $pass_query);
$ts->selectServer($port_ts);

$ts->setName($nom_bot);

while (true) {

    sleep(1);

    $clientList = $ts->clientList("-ip -groups");

    if (is_array($clientList['data']) && sizeof($clientList['data']) > 0) {
        foreach ($clientList['data'] as $val) {

            $groups = explode(",", $val['client_servergroups']);

            if (is_array($ignore_groups)) {

                foreach ($ignore_groups as $ig) {

                    if (in_array($ig, $groups) || ($val['client_type'] == 1)) {

                        continue;
                    }
                }
            } else {

                if (in_array($ignore_groups, $groups) || ($val['client_type'] == 1)) {
                    continue;
                }
            }

            $file = file_get_contents('https://api.xdefcon.com/proxy/check/?ip=' . $val['connection_client_ip'] . '');

            $file = json_decode($file, true);

            if ($file['message'] == "Proxy detected.") {
                $ts->clientKick($val['clid'], "server", $msg_kick);
            }
        }
    } else {
        echo "There might be no data in Client List";
    }
}
Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    Hey Tanks for the edit and the fast relpy. Id added the code with the size of and for the first point it workd but then i just got this thing : There might be no data in Client List – kaitomar Apr 29 '19 at 09:59