Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The data is already in the library, so this is all it takes:
/**
* API function to return the continent code for a given IP. Defaults to using the
* current user's IP if not specified.
*
* @return string
*/
function geoip_continent_code($ip = NULL) {
$ip = $ip ? $ip : geoip_ip_address();
$gi = geoip_instance();
if (!$gi) {
return FALSE;
}
$id = geoip_country_id_by_addr($gi, $ip);
$continent = isset($gi->GEOIP_CONTINENT_CODES[$id]) ? $gi->GEOIP_CONTINENT_CODES[$id] : '';
geoip_close($gi);
if (variable_get('geoip_debug', FALSE) && !empty($_GET['geoip_debug'])) {
drupal_set_message(t('GeoIP reports continent: %continent', array('%continent' => $continent)));
}
return $continent;
}