Damn, I didn't realize this thread was here. I'll post this PHP awesomeness in here anyways. It's another way to get GEOIP info fast and easy.
Here's the class
Here's the include
And here's what you put in your page..
See, it's simple as fuck. I know I just saw something else floating around here but this script is awesome.
Today I Searched | PHP Geo IP Address Lookup
Enjoy it
Here's the class
PHP:
/*
Provided by http://www.todayisearched.com
*/
class GeoIP {
/*
Returns all possible Geo Ip information in an associative array. The following pieces of information
are returned:
IP - IP ADDRESS LOOKED UP
CODE - COUNTRY CODE
COUNTY - COUNTRY NAME
FLAG - PATH TO IMAGE OF THE COUNTRY'S FLAG
CITY - CITY NAME
REGION - STATE NAME
ISP - ISP NAME
LAT - LATITUDE CORDINATE
LNG - LONGITUDE CORDINATE
USAGE:
$ipinfo = GeoIP :: getGeoArray('xxx.xxx.xxx.xxx');
echo $ipinfo['CITY'] . ', ' . $ipinfo['STATE'];
*/
public static function getGeoArray($ip) {
$file = "http://www.ipgp.net/api/xml/". $ip;
$xml_parser = xml_parser_create();
$fp = fopen($file, "r");
$data = fread($fp, 80000);
xml_parse_into_struct($xml_parser, $data, $vals);
$iplookup = array();
foreach ($vals as $v) {
if (isset($v['tag']) && isset($v['value'])) {
$iplookup[$v['tag']] = $v['value'];
}
}
xml_parser_free($xml_parser);
fclose($fp);
return $iplookup;
}
//shortcut to get the city name
public static function getCity($ip) {
$a = self :: getGeoArray($ip);
return $a['CITY'];
}
//shortcut to get the state name
public static function getState($ip) {
$a = self :: getGeoArray($ip);
return $a['REGION'];
}
}
Here's the include
PHP:
include_once "geoip.php";
$ipinfo = GeoIP :: getGeoArray($_SERVER['REMOTE_ADDR']);
And here's what you put in your page..
PHP:
echo 'Hello, Your City And State Is ' . $ipinfo['CITY'] . ', ' . $ipinfo['REGION'];
See, it's simple as fuck. I know I just saw something else floating around here but this script is awesome.
Today I Searched | PHP Geo IP Address Lookup
Enjoy it