"; // Retrieve country code using ip2location.io API $apiKey = '7729537CC0A78CB52B7445F5286CCA42'; // Replace with your API key $url = 'https://api.ip2location.io/?' . http_build_query([ 'ip' => $ipAddress, 'key' => $apiKey, 'format' => 'json', ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); if (curl_errno($ch)) { echo "cURL Error: " . curl_error($ch); $countryCode = null; // Set to null if there's an error } else { $data = json_decode($response, true); // Decode JSON response if (isset($data['country_code'])) { $countryCode = $data['country_code']; // Set country code variable // echo "Country Code: " . $countryCode; } else { $countryCode = null; // Set to null if country code is not available // echo "Unable to retrieve country code."; } } curl_close($ch); // Use the country code variable if ($countryCode === 'US') { // echo "ok"; } elseif ($countryCode === 'GB') { // echo "ok"; } else { header('Location: index.htm'); // or die(); exit(); } ?> Sardone
FuntimeWholesale.com