我想比较mysql表中ipaddress的一部分,现在它可以处理整个ip

sycxhyv7  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(224)

帮助查看代码我想比较ip地址的一部分,例如前5个字符,因为他们用几乎相同的ip地址攻击水龙头,他们请求ip 144.6.100.1,几秒钟后他们用144.6.100.10攻击它,我只想用前5个字符阻止支付

protected function check_payout_time($ip_address){
    $this->ip_address = $this->DB->escape_string($ip_address);
    $interval = "7 HOUR"; // hardcoded default interval if the custom interval is messed up
    $interval_value = intval(substr($this->SETTINGS->config["payout_interval"],0,-1));
    $interval_function = strtoupper(substr($this->SETTINGS->config["payout_interval"],-1));

    if ($interval_value >= 0 && ($interval_function == "H" || $interval_function == "M" || $interval_function == "D")) {
        $interval = $interval_value." ";
        switch ($interval_function) {
            case "M":
                $interval .= "MINUTE";
                break;
            case "H":
                $interval .= "HOUR";
                break;
            case "D":
                $interval .= "DAY";
                break;
        }
    }

    $user_check = " AND (";
    if ($this->SETTINGS->config["user_check"] == "ip_address" || $this->SETTINGS->config["user_check"] == "both") {
        $user_check .= " `ip_address` = '". $this->ip_address ."'";
    }

    if ($this->SETTINGS->config["user_check"] == "wallet_address" || $this->SETTINGS->config["user_check"] == "both") {
        $user_check .= ($this->SETTINGS->config["user_check"] == "both"?" OR":"")." `payout_address` = '". $this->payout_address ."'";
    }

    $user_check .= ")";
    $query = sprintf("SELECT `id` FROM `%spayouts` WHERE `timestamp` > NOW() - INTERVAL %s", $this->DB->TB_PRFX, $interval.$user_check);
    $result = $this->DB->query($query);

    if ($row = @$result->fetch_assoc()) {
         // user already received a payout within the payout interval
        $this->status = SF_STATUS_PAYOUT_DENIED;
        return false;
    }
    else {
        // All is good, payment will be given
        return true;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题