You are here
Home > Php > Convert IP Address to Location in PHP

Convert IP Address to Location in PHP

Hello Friends, Today I am going to share how to Convert IP Address to Location in PHP. Actually recently I required to find Country Code from an IP Address in one of my project, and I found the solution on Internet and I thought to share with you. This code basically work on web service provided by http://www.geoplugin.net and web service url is http://www.geoplugin.net/json.gp

Using this web service we can not only get Country code but also Country name, State, City, Address, Continent, etc. This web service also provides GPS longitude and latitude but this is not implement in the given ip_info function but you can implement if you need by having idea from ip_info function.

This web service takes IP address as parameter and gives json as response. We can call web service like http://www.geoplugin.net/json.gp?ip=XXX.XXX.XXX.XXX(we can use both IPv4 and IPv6 ip addresses).

So Here is the code

Output

Convert IP Address to Location in PHP

Referrence

https://stackoverflow.com/questions/12553160/getting-visitors-country-from-their-ip

Thanks

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top