Please Help to use API [Newbie]

General Discussion about IP Address Lookup caveats, technology, ideas, etc.

Moderator: Moderators

Please Help to use API [Newbie]

Postby rajkumar on Wed Feb 15, 2006 3:08 am

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]
rajkumar
n00b
 
Posts: 3
Joined: Wed Feb 15, 2006 2:55 am

Try out this!!

Postby agarwalcp on Thu Feb 16, 2006 8:40 am

: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
agarwalcp
n00b
 
Posts: 1
Joined: Thu Feb 16, 2006 8:35 am
Location: INDIA

Re: Try out this!!

Postby rajkumar on Thu Feb 16, 2006 11:05 am

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
rajkumar
n00b
 
Posts: 3
Joined: Wed Feb 15, 2006 2:55 am

Postby pf69 on Fri Mar 17, 2006 12:22 pm

is there any way to print only teh country name?
like: BRAZIL
instead of: Country: BRAZIL (BR)
pf69
n00b
 
Posts: 2
Joined: Fri Mar 17, 2006 12:19 pm

Postby rajkumar on Fri Mar 17, 2006 12:26 pm

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]
rajkumar
n00b
 
Posts: 3
Joined: Wed Feb 15, 2006 2:55 am

Postby pf69 on Fri Mar 17, 2006 12:50 pm

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?
pf69
n00b
 
Posts: 2
Joined: Fri Mar 17, 2006 12:19 pm

Postby Mister on Sun Mar 19, 2006 2:52 pm

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 "("


<?
echo "Creating GE-GEOIP";
echo "Using hostip.info db :-)";
?>
Mister
n00b
 
Posts: 14
Joined: Sun Mar 19, 2006 2:40 pm
Location: SE


Return to IP Address Lookup

Who is online

Users browsing this forum: No registered users and 4 guests

cron