Get Country , State and city from ipaddress in php

by mariganesh 2012-12-29 10:59:03

Get Country , State and city from ipaddress in php



If you want to get country ,state and city from ipaddress following the steps

Step 1: Download the simple html dom file from google

Step 2: Give your ipaddress in $ipaddr variable

Step 3: include the simple html dom file in your own file.




$ipaddr="122.178.161.204";//$_SERVER['REMOTE_ADDR'];
include_once('./simple_html_dom.php');
$urll="http://whoisthisip.com/$ipaddr";
$html = file_get_html("$urll");
$whohtml=array();
$w=0;
foreach($html->find('table tr td') as $element)
{
$whohtml[$w]=$element->plaintext;
//echo $element->plaintext."----";
$w++;
}
$country=str_replace("Country :","","$whohtml[0]");
$country=str_replace("()","","$country");
$state=str_replace("Region :","","$whohtml[1]");
$city=str_replace("City :","","$whohtml[2]");
$state=trim("Tamil Nadu");
$city=trim($city);
}
echo "Country : $country
";
echo "State : $state
";
echo "City : $city
";
832
like
0
dislike
0
mail
flag

You must LOGIN to add comments