localization - Call reference for country in GeoLite2 using PHP -
i'm trying utilize free maxmind geolite2 code able determine country of specific ip address.
i using composer-free method posted here: get localized name of users city via maxmind geolite2 free
i'm sure incredibly simple, can't figure out how pass ip address , have homecoming country.
after $reader = new reader... line have $place = $reader->country('##.###.##.###'); (where #'s actual ip address numbers) , it's not working. tried replacing 'country' 'city' , didn't work either. i'm sure simple, i'm not sure parameters need using country returned.
the error shown in error log 'php fatal error: phone call undefined method maxmind\db\reader::city() in <<< path benchmark.php >>>)'
any ideas/suggestions appreciated.
there's no city() or country() functions defined in files you're including (based on reply linked to.) instead you're supposed utilize get() ip geographic information, so:
require_once __dir__ . '/' . 'db/reader.php'; require_once __dir__ . '/' . 'db/reader/decoder.php'; require_once __dir__ . '/' . 'db/reader/invaliddatabaseexception.php'; require_once __dir__ . '/' . 'db/reader/metadata.php'; require_once __dir__ . '/' . 'db/reader/util.php'; // new 2014/09 utilize maxmind\db\reader; $mmdb= 'geolite2-country.mmdb'; $reader = new reader( __dir__ . '/' . $mmdb ); $ipdata = $reader->get('##.###.##.###'); echo $ipdata['country']['names']['en']; where replace ##.###.##.### ip want info for. requires have required code files , geolite2-country.mmdb
so finish steps be:
download maxmind-db-reader-php https://github.com/maxmind/maxmind-db-reader-php copydb folder found in src/maxmind directory file containing above code. download geolite2 country maxmind db http://dev.maxmind.com/geoip/geoip2/geolite2/ unzip downloaded gzip , re-create geolite2-country.mmdb file same directory file containing above code. you should able run above code! create sure replace ##.###.##.### real ip. php localization geoip maxmind
No comments:
Post a Comment