Blog : Reading from a txt file to JavaScript -html

Reading from a txt file to JavaScript -html

inShare
 
I have already posted a script to find out the visitor’s ip. This one is similar to that one but has some additional functionality. This script uses the free IP Lookup API(Application Program Interface) provided by hostip . The script fetches the visitor’s IP from $_SERVER['REMOTE_ADDR'] and then passes on the ip to the HostIP.info API. Finally, the script processes the data returned by HostIp’s API.

17
IP Lookup - MyCoding.net
  /*
  PHP IP Lookup script
  Author: Vlad
  Website: www.mycoding.net
  */
  function getGeo(){
  $ip = $_SERVER['REMOTE_ADDR'];
  $info = file_get_contents("http://api.hostip.info/get_html.php?ip=$ip");
  $country = explode("\n",$info);
  $country[0] = str_replace("Country:","",$country[0]);
  return $country[1].",".$country[0];
  }
  echo "Your IP: ".$_SERVER['REMOTE_ADDR']."
".getGeo();
 
?>
Demo: IP Lookup – MyCoding.net