// -------- GET IP ADDRESS -------------------------------------------------
// Retrieve visitor's IP address
$IPaddr = $REMOTE_ADDR;
$IPnum = Dot2LongIP($IPaddr);
// Convert IP address to IP number
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
// -------- CHECK FIRST IP-LAT-LONG DATABASE -------------------------------
// Set parameters for lat-long SQL-server
$server= "localhost"; /* Address of 1&1 database server */
$user= "dbo144306095"; /* Database username */
$password= "ndea43466872"; /* Database Password */
$database= "db144306095"; /* name of database */
// Connect to lat-long database
MYSQL_CONNECT($server, $user, $password) or die ( "
Server unreachable
");
MYSQL_SELECT_DB($database) or die ( "
Database non existent
");
// Perform query on lat-long database
$query = "SELECT countryLONG, ipREGION, ipCITY, ipLATITUDE, ipLONGITUDE FROM IPCITYLATLONG
WHERE (ipFROM <= $IPnum) AND (ipTO >= $IPnum)";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Retrieve contents of query
$row = mysql_fetch_row($result);
// Close connection to lat-long database
MYSQL_CLOSE();
// -------- IF NO MATCH CHECK SECOND IP-LAT-LONG DATABASE -----------------
// Check for zeroes
if ( empty($row[3]) && empty($row[4])) {
// Set parameters for lat-long SQL-server
$server= "localhost"; /* Address of 1&1 database server */
$user= "dbo144306122"; /* Database username */
$password= "ndea43466872"; /* Database Password */
$database= "db144306122"; /* name of database */
// Connect to lat-long database
MYSQL_CONNECT($server, $user, $password) or die ( "
Server unreachable
");
MYSQL_SELECT_DB($database) or die ( "
Database non existent
");
// Perform query on lat-long database
$query = "SELECT countryLONG, ipREGION, ipCITY, ipLATITUDE, ipLONGITUDE FROM IPCITYLATLONG
WHERE (ipFROM <= $IPnum) AND (ipTO >= $IPnum)";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Retrieve contents of query
$row = mysql_fetch_row($result);
// Close connection to lat-long database
MYSQL_CLOSE();
}
// Exit if still no match found
if ( empty($row[3]) && empty($row[4])) exit;
// -------- WRITE RECORD IN VISIT DATABASE --------------------------------
// Set parameters for map SQL-server
$server= "localhost"; /* Address of 1&1 database server */
$user= "dbo144304509"; /* Database username */
$password= "ndea43466872"; /* Database Password */
$database= "db144304509"; /* name of database */
$table= "userlocations"; /* name of table */
// Connect to map database
MYSQL_CONNECT($server, $user, $password) or die ( "
Server unreachable
");
MYSQL_SELECT_DB($database) or die ( "
Database non existent
");
// Insert record in map database
$row[2]= addslashes($row[2]);
$query= "INSERT IGNORE INTO $table (lat,lon,country,region,city) VALUES ('$row[3]','$row[4]','$row[0]','$row[1]','$row[2]')";
$result= mysql_query($query) or die('Insert failed: ' . mysql_error());
// Close connection to map database
MYSQL_CLOSE();
?>