Doing a GeoIP lookup and setting custom routing
There might be times when our app needs to give people different pages depending on which country they're in. Using Laravel and MaxMind's GeoIP data, we can lookup a person's country, based on their IP address, and then redirect them to the page we need.
Getting ready
For this recipe, we'll just need a working Laravel 4 installation.
How to do it...
To complete this recipe, follow these steps:
Open the
composer.json
file and update therequire
section, so it looks like the following snippet:"require": { "laravel/framework": "4.0.*", "geoip/geoip": "dev-master" },
In the command line window, run the composer update with the following command:
php composer.phar update
Go to http://dev.maxmind.com/geoip/legacy/geolite/ and download the latest GeoLite Country database. Unzip it and put the
GeoIP.dat
file in the root of our app.In the
app/config
directory, create a file namedgeoip.php
with the following code:<?php return array( 'path' =>...