spacer spacer
spacer

simple country lookup script using the www.hostip.info database
30.06.2009


here's an easy function to look up the country of a website visitor (ip adress) using the free database from www.hostip.info.

function haxGetCountryByIp(){

$connect=mysql_connect("localhost","root","");

$ip=explode(".",$_SERVER['REMOTE_ADDR']);

$ip1=$ip[0];
$ip2=$ip[1];
$ip3=$ip[2];
$ip4=$ip[3];

$qry="SELECT `name` FROM `countries`, ip4_".$ip1." WHERE `b`='".$ip2."' AND `c`='".$ip3."' AND countries.id=ip4_".$ip1.".country"; $get=mysql_db_query("NAMEOFYOURHOSTIPINFODATABASE","$qry",$connect);

list($country)=mysql_fetch_row($get);
if($country) { return $country; }
else { return false; }

}

$country=haxGetCountryByIp();
echo $country;
Vienna @ 16,6 °C [5,7m/s]
this site was rendered in 0.48195 seconds with a total # of 22 167 881 sites so far.
676048 of which came from registered users. Impressum @ u2.hax.at