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.
$json = file_get_contents('http://freegeoip.appspot.com/json/126.96.36.199'); $expression = json_decode($json); print_r($expression);
stdClass Object ( [status] => 1 [ip] => 188.8.131.52 [countrycode] => US [countryname] => United States [regioncode] => CA [regionname] => California [city] => Mountain View [zipcode] => 94043 [latitude] => 37.4192 [longitude] => -122.057 )
To get countryname
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.
Country: UNITED STATES (US)
City: Sugar Grove, IL
Use the free IP geolocation webservice
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂