Page 1 of 1

Please Help to use API [Newbie]

PostPosted: Wed Feb 15, 2006 3:08 am
by rajkumar
Dear Admin,

First thanks a lot for great service..!

I am trying to display the flag, country info for IPs retrived from mysql, but I could show only the flag. I do in this way [PHP],

Code: Select all

$flag= "<A HREF="http://www.hostip.info">
            <IMG SRC="http://api.hostip.info/flag.php?ip=$ip" ALT="IP Address Lookup">
             </A>";
echo "$flag";




Works fine. But,

Code: Select all

$countryinfo="http://api.hostip.info/get_html.php?ip=$ip";
echo "$countryinfo";



Does not display the country info, but the full url [http://api.hostip.info/get_html.php?ip=65.55.246.48]

How do I display the country info in my page???

[rajkumar]

Try out this!!

PostPosted: Thu Feb 16, 2006 8:40 am
by agarwalcp
:lol: Yah I too banged my coooool head .. and finally got it........

Just copy paste......

<?
$ppp = "http://www.hostip.info/api/get.html?ip=$REMOTE_ADDR";
$result = file($ppp);
echo $result[0];
?>

Regards,
Chetna

Re: Try out this!!

PostPosted: Thu Feb 16, 2006 11:05 am
by rajkumar
Excellent..! It works fine..! Now I control the display in this way,

Code: Select all

  $flag1 = "<img src='http://api.hostip.info/flag.php?ip=$ip' width='20' height='13'>";
  $ipinfo  = "http://www.hostip.info/api/get.html?ip=$ip&position=true";
  $ipinfo1 = file($ipinfo);
  $con = explode(": ", $ipinfo1[0]);
  $con1 = $con[1];
  $city = explode(": ", $ipinfo1[1]);
  $city1 = $city[1];
  $lati =  explode(": ", $ipinfo1[2]);
  $lati1 = $lati[1];
  $longi =  explode(": ", $longi1[3]);
  $longi1 = $longi[1];

print "
   Flag      : $flag1 <br>
   Country      : $con1 <br>
   City      : $city1 <br>
   Logitude      : $longi1 <br>
   Latitude      : $lati1 <br>
   ";


What is still troubling is the speed at which it fetches the data..! Takes some time to get the data, when there are many IPs to be traced. But keeping the entire database locally is not possible as it ~500MB..:(

Anyway, thanks agarwalcp.

[rajkumar]

agarwalcp wrote::lol: Yah I too banged my coooool head .. and finally got it........

Just copy paste......

<?
$ppp = "http://www.hostip.info/api/get.html?ip=$REMOTE_ADDR";
$result = file($ppp);
echo $result[0];
?>

Regards,
Chetna
Code: Select all

PostPosted: Fri Mar 17, 2006 12:22 pm
by pf69
is there any way to print only teh country name?
like: BRAZIL
instead of: Country: BRAZIL (BR)

PostPosted: Fri Mar 17, 2006 12:26 pm
by rajkumar
pf69 wrote:is there any way to print only teh country name?
like: BRAZIL
instead of: Country: BRAZIL (BR)



Yes. It is possible. Use simple explode function to print only the characters before "(".

Regards,

[rajkumar]

PostPosted: Fri Mar 17, 2006 12:50 pm
by pf69
rajkumar wrote:
pf69 wrote:is there any way to print only teh country name?
like: BRAZIL
instead of: Country: BRAZIL (BR)



Yes. It is possible. Use simple explode function to print only the characters before "(".

Regards,

[rajkumar]
sorry for my stupidity...but how do I do that?

PostPosted: Sun Mar 19, 2006 2:52 pm
by Mister
Code: Select all
$flag1 = "<img src='http://api.hostip.info/flag.php?ip=$ip' width='20' height='13'>";
  $ipinfo  = "http://www.hostip.info/api/get.html?ip=$ip&position=true";
  $ipinfo1 = file($ipinfo);
  $con = explode(": ", $ipinfo1[0]);
  $con1 = $con[1];
  $city = explode(": ", $ipinfo1[1]);
  $city1 = $city[1];
  $lati =  explode(": ", $ipinfo1[2]);
  $lati1 = $lati[1];
  $longi =  explode(": ", $longi1[3]);
  $longi1 = $longi[1];

print "
   Flag      : $flag1 <br>
   Country      : $con1 <br>
   City      : $city1 <br>
   Logitude      : $longi1 <br>
   Latitude      : $lati1 <br>
   ";

Say you using that code above.. and $con1 is the Country right!
Look at the code
Code: Select all
$con = explode(": ", $ipinfo1[0]);
  $con1 = $con[1];

So we can "explode the con[1]" con[1] is now = BRAZIL (BR)
use the code
Code: Select all
$split = explode(" ",  $con[1]);//Use " " insted else $con_short = BR)
$con_long = $split[0]; // is now BRAZIL
$con_short = $split[1]; //is now (BR) could be BR) if you explode "("