<?php

function locateIp(){
	if (!@$_SESSION['ip_data'] || @$_POST['ip']) {
		$ip = (preg_match('/^(\d{1,3}\.){3}\d{1,3}$/', @$_POST['ip'])) ? @$_POST['ip'] : $_SERVER['REMOTE_ADDR'];
		$d = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml");
	 
		//Use backup server if cannot make a connection
		if (!$d){
			$backup = file_get_contents("http://backup.ipinfodb.com/ip_query.php?ip=$ip&output=xml");
			$answer = new SimpleXMLElement($backup);
			if (!$backup) return false; // Failed to open connection
		} else {
			$answer = new SimpleXMLElement($d);
		}
	 
		$_SESSION['ip_data']['ip'] = $ip;
		$_SESSION['ip_data']['country_code'] = (string) $answer->CountryCode;
		$_SESSION['ip_data']['country_name'] = (string) $answer->CountryName;
		$_SESSION['ip_data']['region_name'] = (string) $answer->RegionName;
		$_SESSION['ip_data']['city'] = (string) $answer->City;
		$_SESSION['ip_data']['zippostalcode'] = (string) $answer->ZipPostalCode;
		$_SESSION['ip_data']['latitude'] = (string) $answer->Latitude;
		$_SESSION['ip_data']['longitude'] = (string) $answer->Longitude;
		$_SESSION['ip_data']['timezone'] = (string) $answer->Timezone;
		$_SESSION['ip_data']['gmtoffset'] = (string) $answer->Gmtoffset;
		$_SESSION['ip_data']['dstoffset'] = (string) $answer->Dstoffset;
	}
	return($_SESSION['ip_data']);
}

function IPInfo($ip_data) {
	return ("<b>IP : $ip_data[ip]<br>
	Country code : $ip_data[country_code]<br>
	Country name : $ip_data[country_name]<br>
	Region name : $ip_data[region_name]<br>
	City : $ip_data[city]<br>
	Zip/postal code : $ip_data[zippostalcode]<br>
	Latitude : $ip_data[latitude]<br>
	Longitude : $ip_data[longitude]<br>
	Timezone : $ip_data[timezone]<br>
	GmtOffset : $ip_data[gmtoffset]<br>
	DstOffset : $ip_data[dstoffset]</b>");
}

?>

This source code displayed in HTML format using the freeware source.php by Paul Postuma and Ars Informatica