Get User Location Using IP Address In PHP
Tuesday, Mar 7, 2017
User data like location,ip address,host is sometimes necessary to get to know where your user come from what is his IP address and else. So, in this tutorial we will show you how to get user's complete location using users IP address in PHP with the help of GeoPlugin web service.You may also like get user address using PHP and google map api.
Do you want to create your own website but don't know how to do it. Let's take this course from TreeHouse which is one of the best online course website for developers where you can learn everything from the beginning to the end to create your own website and become the master in creating Websites. Click Here To Get 7 Day Free Trial →
To Get Location It Takes Only one Step:-
- Make a PHP file and define scripting
Step 1.Make a PHP file and define scripting
We make a PHP file and save it with a name location.php
<html> <body> <div id="wrapper"> <?php $ip=$_SERVER['REMOTE_ADDR']; echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip))); ?> </div> </body> </html>
In this step we first get the IP address of the user and then assign it to geoplugin link to get the complete location of the user.You may also like get visitor details using PHP.
Thats all, this is how to get user location using IP address using PHP.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Hello, My Name is Mudit Jain. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of TalkersCode. I started this blog in february 2015 to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers.