![]() ![]()
Since Google’s privacy politics has changed, you can’t use HTML5 Geolocation API if your server doesn’t have HTPPS certificate or user doesn’t allow you check his location. Today I would recommend using Geocoder, a PHP library which makes it very easy to geocode ip addresses as well as postal address data. Once you have the coordinates, you can reverse geocode them to a country code. You can’t use them yet on the Internet Explorer (IE9 will support it, long way to go yet), but in case your audience is mainly on mobile devices or using Safari/Firefox it’s definitely worth to look at it! Check out this one:Īnd of course, depending on your project you might want to look at HTML5 Location features. The database data needs to be updated regularly, though. ![]() Otherwise, there are scripts which are based on local databases on your server. Which one looks the most trustworthy is up to you ? Open geoip.php in a browser and it should display all sorts of GeoIP data for the IP of Google’s DNS (8.8.8.8).There are free, easy APIs you can use, like those: Create a file in your docker build directory named nf, and put the contents below inside: UserId 999999. Finally, you need to configure the geoipupdate tool so it pulls the right databases and puts them in the right location. Sudo cp -a /path/to/my/project/vendor /path/to/www/ The above process follows the official build instructions from MaxMind's repo. The simplest way is to just copy the vendor-directory to your web directory. ![]() ![]() Note that you will need access to the vendor directory from your composer project. #Maxmind geoip php example code#If you want to test if everything works, create a webpage under your document_root (web directory) and add the test code below. Sudo sed -i '/^\ Dynamic Extensions/' /etc/php5/fpm/php.ini Next we need to add the compiled shared library as an extension to PHP and restart FPM. The source code for the extension is bundled with the PHP API we downloaded earlier using composer cd /path/to/my/project/vendor/maxmind-db/reader/ext This extension will vastly improve the performance of doing database lookups from PHP. #Maxmind geoip php example install#sudo add-apt-repository ppa:maxmind/ppaįinally we install the C extension of GeoIP to PHP. Instead of downloading the Github repo, we add Maxmind’s PPA repository for Ubuntu. Traceroute on a Map using Pingdom API, MaxMind, and D3 TechSlides. Install the C library as well (needed by the extension below). Install Maxmind’s GeoIP API for PHP cd /path/to/my/projectĬomposer require geoip2/geoip2:dev-master Install PHP Composer (needed for the PHP API) sudo wget -O /usr/local/bin/composer Sudo mv GeoLite2-City.mmdb /usr/local/share/geoip/ #Maxmind geoip php example free#This tutorial uses the free “Lite” version, but everything should be the same if you use the commercial version as well. Restart Nginx sudo nginx -t
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |