You can use external API's like geoplugin.net
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=76.109.14.196");
echo $xml->geoplugin_countryName ;
Output Country
United States
Full XML Response
76.109.14.196
200
West Palm Beach
FL
561
548
US
United States
NA
26.761600494385
-80.091598510742
FL
Florida
USD
$
1
Simple Function to Get IP
function getIP() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}