You can easily use the defined variables in a script or extension to validate the GeoIP data of the remote address.
Variables defined in Nginx and PHP
Both the city database as well as the country database provide their own constants within PHP
and variables in Nginx
:
GeoIP Country data
Name | PHP Constant | Nginx Variable |
---|---|---|
Country Code | GEOIP_COUNTRY_CODE |
$geoip_country_code |
Country Code 3 | GEOIP_COUNTRY_CODE3 |
$geoip_country_code3 |
Country Code Name | GEOIP_COUNTRY_NAME |
$geoip_country_name |
GeoIP City Lite data
Name | PHP Constant | Nginx Variable |
---|---|---|
City Code | GEOIP_CITY_COUNTRY_CODE |
$geoip_city_country_code |
City Code 3 | GEOIP_CITY_COUNTRY_CODE3 |
$geoip_city_country_code3 |
City Country Name | GEOIP_CITY_COUNTRY_NAME |
$geoip_city_country_name |
City Region | GEOIP_REGION |
$geoip_region |
City | GEOIP_CITY |
$geoip_city |
City Postal Code | GEOIP_POSTAL_CODE |
$geoip_postal_code |
City Continent Code | GEOIP_CITY_CONTINENT_CODE |
$geoip_city_continent_code |
City Latitude | GEOIP_LATITUDE |
$geoip_latitude |
City Longitude | GEOIP_LONGITUDE |
$geoip_longitude |
Testing GeoIP in PHP
To test or see the GeoIP functionality in use, you can use this example script: