<?php
error_reporting(0);
session_start();

$config_antibot['apikey'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //apikey
class Antibot
{
    function apikey($api_key){
        $this->apikey = $api_key;
    }
    function get_client_ip() {
        $ipaddress = '';
        if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
            $ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
        } elseif (isset($_SERVER['HTTP_X_REAL_IP'])) {
            $ipaddress = $_SERVER['HTTP_X_REAL_IP'];
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            $ipaddress = trim($list[0]);
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        } else {
            $ipaddress = '23.200.91.255';
        }
        if ($ipaddress === '::1' || $ipaddress === '127.0.0.1' || $ipaddress === 'UNKNOWN') {
            $ipaddress = '23.200.91.255'; 
        }
        return $ipaddress;
    }
    function httpGet($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout in seconds
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        $response = curl_exec($ch);
        return $response;
    }
    function check(){
        $ip         = $this->get_client_ip();
        $xantiboturl = 'https://xantibot.pw/api/ip-antibot?apikey='.$this->apikey.'&useragent='.urlencode($_SERVER['HTTP_USER_AGENT']).'&ip='.$ip;
        $respons    = $this->httpGet( $xantiboturl );
        $json       = json_decode($respons,true);
        if ( $json['data']['is_blocked'] == 1 || $json['data']['is_blocked'] == true ) {
            return true;
        } else {
            return false;
        }
    }
}
if($_SESSION['check'] == false){
    $Antibot = new Antibot;
    $_SESSION['check']   = true;
    $Antibot->apikey( $config_antibot['apikey'] );
    if($Antibot->check() == true){
        $_SESSION['bot']   = true;
        header("Location: https://google.com/");
        exit();
    }
}
