Get Country information from IP address using PHP

This tutorial will show you how we you can get Country, City, State information from an IP address using PHP. Sometimes we are curious to know the details about a user who has been visiting the web page, then we can use this kind of application to log the visitor’s details into database.

In this tutorial I am passing the IP to an external URL which will actually fetch the information and I will extract the detail information from response HTML.

PHP 5.4
MySQL 5.5
Apace http Server 2.4
Netbeans 7.4 (Optional)

Step 1. Creates a php projects using Netbeans or create a project directory under htdocs.

Step 2. Create a php file called config.php with the below source code in the project directory

Step 3. Create a common.php file with below source code in the project directory

Step 4. Create a PHP web page for displaying the Country information

That’s all. Thanks for reading.

Soumitra Roy Sarkar

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Twitter Facebook  Google Plus Linkedin

Leave a Reply

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