如何在TS3AntiVPN应用程序中正确编写$clientList foreach



我下载了一个TS3AntiVPN,但它是一个错误。我使用运行 Debian 9 Plesk 的 Linux 服务器。

PHP 警告:为 foreach(( 提供的参数无效 /var/www/vhosts/suspectgaming.de/tsweb.suspectgaming.de/antivpn/bot.php 在第 29 行

如何解决此问题?

<?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);
        }
    }
}
?>
您可能在

第一个数组中缺少数据。您可以添加一个 if 语句来检查您的 $clientList['data'] var 中是否有数据:

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

}

或者,您也可以检查数组sizeof();是否大于数字,您可能希望。

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

}

法典

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";
    }
}

最新更新