city($ipAddress);
// Get the country ISO code
$countryCode = $record->country->isoCode;
// Check if the user is from Serbia
if ($countryCode === $targetCountry) {
// Redirect to the specified URL
header(“Location: $redirectUrl”, true, 302);
exit;
} else {
// Display a test message if not from Serbia
echo “
Test Result
“;
echo “
You are from {$record->country->name} (Country Code: $countryCode).
“;
echo “
No redirect triggered. This page is visible because you are not in Serbia.
“;
}
} catch (Exception $e) {
// Handle errors (e.g., invalid IP, database not found)
echo “
Error
“;
echo “
GeoIP2 Error: ” . $e->getMessage() . “
“;
echo “
Check the database path or IP address validity.
“;
}
?>