Find IP address location in php

Hello Friends In this tutorial I am going to show you how to Find IP address location in php,geoplugin.net has provided a open api to get ip address details in array format, You can send request to geoplugin.net with ip address and it’ll return IP address details in serialize format. It is also helpful If you are working on multi lingual project or you are looking for a solution to change website theme banner as per country location, then this tutorial is useful for you. By the below script you can find the user’s ip country, country code, currency, state and latitude , langitude to display ip location on map.



I have created simple online program to find IP address location and displayed on google map. You can download full script and change it as per your need.
find-ip-address-location
First of all create a simple php function to send request on geoplugin.net with ip address and parse response in array format.

function ipInfo($ip) {
	if(isset($ip)) {
      $data = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
	   if($data['geoplugin_status'] == '200') {
	   	return $data;
	   } else {
	   	echo "Bad request!, Error code is ".$data['geoplugin_status']; 
	   }
	} else {
		echo "IP is not set!"; 
	}
}

Now all done you only need to pass Ip Address in this function and it’ll return ip address details in array format.

var_dump(ipInfo('180.151.74.202'));

In the response you’ll see lot’s of data like Ip address region, country, country code, currency, currency symbol, latitude and longitude etc..


See the online demo and download full source code.

DEMO

DOWNLOAD

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

One Reply to “Find IP address location in php”

  1. hi sir now it is working properly for single ipaddress. can u please locate multiple ip address at time when click on submit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.