Hey i tried this code to get the country and IP via PHP (from: http://roshanbh.com.np/2008/07/getti...ss-in-php.html)
[code=php]
function countryCityFrom IP($ipAddr)
{
//function to find country and city from IP address
//Developed by Roshan Bhattarai http://roshanbh.com.np
//verify the IP address for the
ip2long($ipAddr )== -1 || ip2long($ipAddr ) === false ? trigger_error(" Invalid IP", E_USER_ERROR) : "";
$ipDetail=array (); //initialize a blank array
//get the XML result from hostip.info
$xml = file_get_conten ts("http://api.hostip.info/?ip=".$ipAddr);
//get the city name inside the node <gml:name> and </gml:name>
preg_match("@<H ostip>(\s)*<gml :name>(.*?)</gml:name>@si",$ xml,$match);
//assing the city name to the array
$ipDetail['city']=$match[2];
//get the country name inside the node <countryName> and </countryName>
preg_match("@<c ountryName>(.*? )</countryName>@si ",$xml,$matches );
//assign the country name to the $ipDetail array
$ipDetail['country']=$matches[1];
//get the country name inside the node <countryName> and </countryName>
preg_match("@<c ountryAbbrev>(. *?)</countryAbbrev>@ si",$xml,$cc_ma tch);
$ipDetail['country_code']=$cc_match[1]; //assing the country code to array
//return the array containing city, country and country code
return $ipDetail;
}
$IPDetail=count ryCityFromIP('1 2.215.42.19');
echo $IPDetail['country']; //country of that IP address
echo $IPDetail['city']; //outputs the IP detail of the city[/code]
..But Apaches says
Seems to get this everytime i use file_get_conten ts().. Any idea here?
Thanks again!
Frederik
[code=php]
function countryCityFrom IP($ipAddr)
{
//function to find country and city from IP address
//Developed by Roshan Bhattarai http://roshanbh.com.np
//verify the IP address for the
ip2long($ipAddr )== -1 || ip2long($ipAddr ) === false ? trigger_error(" Invalid IP", E_USER_ERROR) : "";
$ipDetail=array (); //initialize a blank array
//get the XML result from hostip.info
$xml = file_get_conten ts("http://api.hostip.info/?ip=".$ipAddr);
//get the city name inside the node <gml:name> and </gml:name>
preg_match("@<H ostip>(\s)*<gml :name>(.*?)</gml:name>@si",$ xml,$match);
//assing the city name to the array
$ipDetail['city']=$match[2];
//get the country name inside the node <countryName> and </countryName>
preg_match("@<c ountryName>(.*? )</countryName>@si ",$xml,$matches );
//assign the country name to the $ipDetail array
$ipDetail['country']=$matches[1];
//get the country name inside the node <countryName> and </countryName>
preg_match("@<c ountryAbbrev>(. *?)</countryAbbrev>@ si",$xml,$cc_ma tch);
$ipDetail['country_code']=$cc_match[1]; //assing the country code to array
//return the array containing city, country and country code
return $ipDetail;
}
$IPDetail=count ryCityFromIP('1 2.215.42.19');
echo $IPDetail['country']; //country of that IP address
echo $IPDetail['city']; //outputs the IP detail of the city[/code]
..But Apaches says
ERROR: Fatal error: Call to undefined function: file_get_conten ts() in c:\apache\htdoc s\test_pages\br owser_getipandc ountry.php on line 13
Seems to get this everytime i use file_get_conten ts().. Any idea here?
Thanks again!
Frederik
Comment