Below url is the api for getting the api for getting city and country name using the ip. But i have used the different parameters like json
$json = file_get_contents(" http://api.ipinfodb.com/v3/ip-city/?key=a2f2062d64fd705bbb32ce4c44e8ebb508d080990528d7cb4f1a0c5e7ddf5c1e&ip=".$ip."&format=json");
$json = json_decode($json,true);
$city=$json['CityName'];
example url below for ip
http://api.ipinfodb.com/v3/ip-city/?key=a2f2062d64fd705bbb32ce4c44e8ebb508d080990528d7cb4f1a0c5e7ddf5c1e&ip=74.125.45.100&format=json