How to get a users location from an IP Address in PHP/Laravel Framework

Jordan Clist, CTO

To make an awesome user experience in today’s globalised world it is important to localise your website for your visitors and users. You may have different languages or translations of your website or you simply want to show content relevant to your users location. The most reliable and simple way to do this is by getting the requested users IP Address and getting the city/country information from IP Find’s API and then redirecting to the correct pages.

You can get the package on github here or install it from composer like this:

composer require tenfef/ipfind-php

use Tenfef\IPFind\IPFind;

$apiKey = "YOUR_API_KEY_HERE"; // get an API key from or pass in NULL if you plan on using < 100/day
$ipfind = new IPFind($apiKey);
$result = $ipfind->fetchIPAddress('');
$country = $result->country;
   "country":"United States",
   "continent":"North America",
   "city":"Mountain View",
   "county":"Santa Clara",

Lookup IP addresses in seconds, get started now

Get Started for free