note 117240 added to book.geoip

From: Date: Fri, 08 May 2015 06:00:28 +0000
Subject: note 117240 added to book.geoip
Groups: php.notes 
Request: Send a blank email to php-notes+get-202471@lists.php.net to get a copy of this message
If you still want to use legacy binaries but also need IPv6 support this should help: In order to support IPv6->Country code easily and without unnecessary files based on the integration above: Grab a copy of the latest legacy IPv6 data (I'm assuming you already have IPv4 binary): wget http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz Decompress and move it to a dir accessible to your web server: gunzip GeoIPv6.dat mv GeoIPv6.dat /etc/usr/share/GeoIP/GeoIPv6.dat Grab a copy of geoip.inc from the Maxmind git dir (https://github.com/maxmind/geoip-api-php/blob/master/src/geoip.inc) and save it somewhere you can access wherever you'll need to run geoip. If you have php5-geoip installed as I did, remove it with sudo apt-get remove php5-geoip; purge as necessary. With the above done you can now test incoming IP address for v4 or v6 and get appropriate results. Example: <?php include_once('geoip.inc'); //set an IPv6 address for testing $ip='2601:8:be00:cf20:ca60:ff:fe09:35b5'; /* test if $ip is v4 or v6 and assign appropriate .dat file in $gi run appropriate function geoip_country_code_by_addr() vs geoip_country_code_by_addr_v6() */ if((strpos($ip, ":") === false)) { //ipv4 $gi = geoip_open("/usr/share/GeoIP/GeoIP1.dat",GEOIP_STANDARD); $country = geoip_country_code_by_addr($gi, $ip); } else { //ipv6 $gi = geoip_open("/usr/share/GeoIP/GeoIPv6.dat",GEOIP_STANDARD); $country = geoip_country_code_by_addr_v6($gi, $ip); } echo $ip . "<br>" . $country; This is specifically for Country, but can easily be replicated for City data. ---- Server IP: 72.52.91.14 Probable Submitter: 2601:8:be00:cf20:ca60:ff:fe09:35b5 ---- Manual Page -- http://php.net/manual/en/book.geoip.php Edit -- https://master.php.net/note/edit/117240 Del: integrated -- https://master.php.net/note/delete/117240/integrated Del: useless -- https://master.php.net/note/delete/117240/useless Del: bad code -- https://master.php.net/note/delete/117240/bad+code Del: spam -- https://master.php.net/note/delete/117240/spam Del: non-english -- https://master.php.net/note/delete/117240/non-english Del: in docs -- https://master.php.net/note/delete/117240/in+docs Del: other reasons-- https://master.php.net/note/delete/117240 Reject -- https://master.php.net/note/reject/117240 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202471) next »