dongliping003116 2019-04-28 20:30
浏览 67

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

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

?>
  • 写回答

1条回答 默认 最新

  • duanlie2709 2019-04-28 21:49
    关注

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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)