Skip to content

Instantly share code, notes, and snippets.

@miteshmap
Created January 3, 2014 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miteshmap/8234883 to your computer and use it in GitHub Desktop.
Save miteshmap/8234883 to your computer and use it in GitHub Desktop.
Get user city /state/ country information from IP Address.
<?php
function getInfo_of_ip($ip){
$url = "http://api.geoio.com/q.php?key=fC3tzSLwbhXWXnTS&qt=geoip&d=comma&q=".$ip;
$timeout = 5;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$d = curl_exec($ch);
curl_close($ch);
$data = explode(',' , $d);
return $data;
}
$info = getInfo_of_ip(192.168.1.54);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment