Country name from PHP

How to get country name from an IP address using PHP without using a commercial GeoIP Region Edition?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1


$json = file_get_contents('');
$expression = json_decode($json);


stdClass Object
    [status] => 1
    [ip] =>
    [countrycode] => US
    [countryname] => United States
    [regioncode] => CA
    [regionname] => California
    [city] => Mountain View
    [zipcode] => 94043
    [latitude] => 37.4192
    [longitude] => -122.057

To get countryname

echo $expression->countryname;


United States

Solution 2

I don’t think you can do it simply using PHP, but I have found a free API solution that you can use. It requires simple post and response.

example post:

example response:
City: Sugar Grove, IL

Solution 3

Use the free IP geolocation webservice

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply