How to find the city and country of the visitor using PHP

How to find the city and country of the visitor using PHP.

Sometimes we need to manage the content or currency based on the visitor’s country. Usually this situation arises to every developer, they try to find a better solution.

I introduce a new Application by which we can get the following information

IP address
Country Code(Ex: IN)
Country Name
Zip or postal code
Time Zone
Achieving this with IPInfoDB is very easy, providing an API for this.

First register for an API at
Get an API key after activating your account
Download the files
Update your API key at line number 4
Then you get all the above info.
Or use the following code.

The array $assocArray will give the above info. for example

will print the City name.
Here we are executing and parsing the URL with PHP, don’t you know this? read the article How to execute a URL in PHP
Sometimes we need to change the flag or Logo as per the country, then think about following lines of code