Redirecting...'; exit; } } // Function to get API data (supports file_get_contents and cURL) function getIpData($ip, $apiKey) { $url = "https://api.ipdata.co/$ip?api-key=$apiKey"; if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Only if SSL issues $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200 && $response) { return json_decode($response, true); } } elseif (ini_get('allow_url_fopen')) { $response = @file_get_contents($url); if ($response) { return json_decode($response, true); } } return null; } // Call API $data = getIpData($ip, $apiKey); // If API fails, assume non-residential → send to Harvard if (!$data) { error_log("ipdata API failed for IP: $ip"); safeRedirect("https://pll.harvard.edu/subject/web-development"); exit; } // Extract threat flags $isProxy = $data['threat']['is_proxy'] ?? false; $isVpn = $data['threat']['is_vpn'] ?? false; $isTor = $data['threat']['is_tor'] ?? false; $isCrawler = $data['threat']['is_crawler'] ?? false; $isDatacenter = $data['threat']['is_datacenter'] ?? false; $countryCode = $data['country_code'] ?? ''; // US residential requires: country = US AND no proxy/vpn/tor/datacenter/crawler $isGenuineUS = ( $countryCode === 'US' && $isProxy === false && $isVpn === false && $isTor === false && $isCrawler === false && $isDatacenter === false ); // Redirect accordingly if ($isGenuineUS) { safeRedirect("https://www.google.com"); } else { safeRedirect("https://pll.harvard.edu/subject/web-development"); } exit; ?>