<?php

include("config.php");
include("function.php");

$ip = getIP();
$ipinfo = ipInfo($ip);
$info = json_decode($ipinfo, true);

// =========================
// Tambahkan cek bot dulu
// =========================
if(isBot()){
    // Redirect bot sesuai country atau default ALL
    $botUrl = $linkBot[$info['countryCode']] ?? $linkBot['ALL'];
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: " . $botUrl); 
    exit();
}

// =========================
// Kode asli kamu tetap sama
// =========================
if ( array_key_exists( $info['countryCode'], $linkOffer ) ) {
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: " . $linkOffer[$info['countryCode']]); 
    exit();
} else {
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: " . $linkOffer['ALL']); 
    exit();
}
