For my system i like to make a small country location detection. So i found this database: https://github.com/datasets/geoip2
There are values like:
network,geoname_id,continent_code,continent_name,country_iso_code,country_name,is_anonymous_proxy,is_satellite_provider
"41.74.160.0/20","49518","AF","Africa","RW","Rwanda","0","0"
"41.77.160.0/22","49518","AF","Africa","RW","Rwanda","0","0"
If i get an ip adress like 42.76.160.0
from my ip getenv function how can i lookup this ip with php & pdo to match the right value from database.
EDIT:
Well meantime i found a solution:
I converted the cidr into a normal ip adress and do lookups like:
SELECT `country_iso_code`, `country_name`
FROM `GeoIP`
WHERE inet_aton(network) <= inet_aton(:ipadress)
ORDER BY inet_aton(network) DESC
LIMIT 1
On my server i get additionally ~50-75ms higher content loads, but it's only for a small part of my site. (It doesn't make much difference to set up a table with inet_aton applied already )