provider = new Reader( $db_path ); } /** * Convert IP address to country information. * * @param string $ip IP address to lookup. * * @return array|false Country data array with 'iso' and 'name' keys, or false on failure. * @throws Reader\InvalidDatabaseException When database format is invalid. */ public function ip_to_country( $ip ) { $info = $this->provider->get( $ip ); // Try country first, then fall back to registered_country. $country_data = null; if ( isset( $info['country'] ) && is_array( $info['country'] ) ) { $country_data = $info['country']; } elseif ( isset( $info['registered_country'] ) && is_array( $info['registered_country'] ) ) { $country_data = $info['registered_country']; } if ( null === $country_data ) { return false; } return array( 'iso' => $country_data['iso_code'] ?? '', 'name' => $country_data['names']['en'] ?? '', ); } }