How to use MaxMind GeoIP in PHP?

I am using the binary version of the MaxMind GEOIPCITY database. The following code gives me all the necessary information about my visitors:

include("geoipcity.inc"); include("geoipregionvars.php"); $gi = geoip_open("GeoLiteCity.dat", GEOIP_STANDARD); print_r( geoip_db_get_all_info() ); $record = geoip_record_by_addr($gi, $user_ip); print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "<br /><br />"; print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "<br /><br />"; print $record->city . "<br /><br />"; print $record->postal_code . "<br /><br />"; print $record->latitude . "<br /><br />"; print $record->longitude . "<br /><br />"; print $record->metro_code . "<br /><br />"; print $record->area_code . "<br /><br />"; print $record->continent_code . "<br /><br />"; geoip_close($gi); 

I really don't need anything except network speed, ISP, etc.

My problem: there are parts of my site where I need to display all cities under a specific state or all states / regions in a specific country. For example, I need to do this on the registration form.

Is there no way to get these lists by querying a binary? or do i need to handle all this from the mysql version?

I would prefer to use only the binary version, as it’s faster, but now I’m not sure if all zip codes are displayed under a certain city or all states in a certain country, etc. possible without using the mysql version. Do I need to use both?

 http://www.maxmind.com/app/php http://geolite.maxmind.com/download/geoip/api/php/ 
+4
source share
3 answers

The GeoIP database is for one purpose and only one purpose: to return location information for the input IP address. This is not a general-purpose GIS database, and will not work for this purpose, as there are several places that will not be returned for any IP address. (For example, a small town without a local Internet service may not appear at all in their database, since any IP address in this city is likely to be categorized under another nearby city.)

Maxmind has a separate database of Cities of the World with a Population, which is most likely to be suitable for this purpose: http://www.maxmind.com/app/worldcities

+3
source

I just wrote a linux daemon to serve geoinformation requests at the MaxMind level. Each request takes 3 microseconds, and during operation, the server takes about 550 MB of RAM on a 64-bit machine (and 300 MB on a 32-bit machine).

https://github.com/homer6/geoipd

I am sure that you can change it to indexes as well. Let me know if you need help, and I will be happy to help you change it.

Hope this helps ...

+2
source

Maxmind's binary db is probably not intended for this purpose. Try downloading their .csv file, export it to the database, and then index the location table in the status field. Then you can easily select all cities from one state.

0
source

Source: https://habr.com/ru/post/1383919/


All Articles