Skip to content

Instantly share code, notes, and snippets.

@hn-support
Last active January 14, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hn-support/93d1d5d32f9fa8878881b1ce25eb047b to your computer and use it in GitHub Desktop.
Save hn-support/93d1d5d32f9fa8878881b1ce25eb047b to your computer and use it in GitHub Desktop.
How to use geoip data in php on hypernodes
<?php
/*
This script is a basic example of how to use GeoIP data in PHP.
It returns an overview of all available constants retrieved from the Maxmind GeoIP databases.
*/
$elements = array(
"country_code" => getenv('GEOIP_COUNTRY_CODE'),
"country_code3" => getenv('GEOIP_COUNTRY_CODE3'),
"country_name" => getenv('GEOIP_COUNTRY_NAME'),
"city_country_code" => getenv('GEOIP_CITY_COUNTRY_CODE'),
"city_country_code3" => getenv('GEOIP_CITY_COUNTRY_CODE3'),
"city_country_name" => getenv('GEOIP_CITY_COUNTRY_NAME'),
"region" => getenv('GEOIP_REGION'),
"city" => getenv('GEOIP_CITY'),
"postal_code" => getenv('GEOIP_POSTAL_CODE'),
"city_continent_code" => getenv('GEOIP_CITY_CONTINENT_CODE'),
"latitude" => getenv('GEOIP_LATITUDE'),
"longitude" => getenv('GEOIP_LONGITUDE'),
);
echo "<pre>";
foreach ($elements as $name => $data) {
printf("%-30s %s\n", $name, $data);
}
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment