['timeout' => 5, 'ignore_errors' => true]]); $r = @file_get_contents($url, false, $ctx); if ($r !== false) { $country = strtoupper(trim($r)); if (preg_match('/^[A-Z]{2}$/', $country)) { @file_put_contents($cacheFile, $country); return $country; } } return null; // lookup gagal → dianggap "di luar" } // ---------- Logging (opsional) ---------- function logit(string $file, string $msg): void { if ($file !== '') { @file_put_contents($file, '[' . date('c') . '] ' . $msg . PHP_EOL, FILE_APPEND | LOCK_EX); } } // ---------- EKSEKUSI ---------- $ip = real_ip(); $country = get_country($ip, $IPINFO_TOKEN, $CACHE_TTL); if ($country === 'ID') { logit($LOG_FILE, "INDO $ip -> " . $GLOBALS['LINK_INDO']); header('Location: ' . $GLOBALS['LINK_INDO'], true, 302); } else { // Non-Indonesia ATAU lookup gagal → aman, arahkan ke web utama logit($LOG_FILE, "OTHER ($country) $ip -> " . $GLOBALS['LINK_UTAMA']); header('Location: ' . $GLOBALS['LINK_UTAMA'], true, 302); } exit;