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

Php 如何在TS3AntiVPN应用程序中为$clientList正确编写foreach?,php,Php,我下载了一个TS3AntiVPN,但它显示了一个错误。我使用的是运行Debian9Plesk的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 sup

我下载了一个TS3AntiVPN,但它显示了一个错误。我使用的是运行Debian9Plesk的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) {


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

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


}
或者您也可以检查
sizeof()大于一个数字,您可能需要

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


}
代码
编辑和快速重新复制的可能副本。我添加了大小为和的代码,第一次工作时,我得到了一个结果:客户端列表中可能没有用于编辑和快速重新打印的数据。我添加了大小为和的代码,第一次工作时,我得到了一个结果:客户端列表中可能没有数据