Page 1 of 1
IP to Location?
Posted: Wed Sep 27, 2006 3:26 pm
by $var
Assuming I have nabbed a users IP address with $_SERVER['SERVER_ADDR']; ...
what can i realistically do with this?
using code, not ARIN, how do i match it up with their geography to sync up ads, weather, and other custom options without asking for their ZIP/Postal codes?
Posted: Wed Sep 27, 2006 3:43 pm
by Luke
reliably, you can't.
Posted: Wed Sep 27, 2006 4:40 pm
by Benjamin
Posted: Thu Sep 28, 2006 9:29 am
by $var
okay, ninja space goat i can understand that like with http_ref or any other global type server setting for that matter, there is a degree of unreliability, but this MaxMind was bang on for the IP I fed it.
Say, i was looking for an unreliable way to process these, what are some functions that might help me narrow geography for IP.
i have seen a few programs offering these services, displaying city, longitude, latitude... sometimes even postal codes
is this mindmax just querying the IANA? see the demo, it's pretty detailed.
Posted: Thu Sep 28, 2006 9:43 am
by JayBird
It was wrong for my IP address
Posted: Thu Sep 28, 2006 10:02 am
by Benjamin
How far off was it?
Posted: Thu Sep 28, 2006 10:07 am
by $var
i think that mine is particularily easy to read, only because when you ping it it comes up as:
bas16-toronto63-1177909579
perhaps because the city name is in the response?
how far off was it for you JayBird?
Posted: Thu Sep 28, 2006 10:53 am
by $var
i was given this link on another board to check out and it gives some more insight on the process.
http://www.ip2nation.com/
Code: Select all
<?php
$server = ''; // MySQL hostname
$username = ''; // MySQL username
$password = ''; // MySQL password
$dbname = ''; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
country
FROM
ip2nation
WHERE
ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
ORDER BY
ip DESC
LIMIT 0,1';
list($country) = mysql_fetch_row(mysql_query($sql));
switch ($country) {
case 'se':
// Get the swedish to a swedish newssite
header('Location: http://www.thelocal.se/');
exit;
case 'us':
// And let the folks from american go to CNN
header('Location: http://www.cnn.com/');
exit;
default:
// The rest can go to BBC
header('Location: http://www.bbc.co.uk/');
exit;
}
?>
Posted: Sun Oct 01, 2006 12:36 pm
by brendandonhue
These scripts are just checking a list of IP ranges that are known to match up with certain locations. PEAR has a library that shows you how to use MaxMind's database to do this.
Posted: Sun Oct 01, 2006 5:58 pm
by Chris Corbyn
MaxMind seemed to work relatively well.
It told me I'm in Manchester on my dial-up connection but when trying two static IPs against it it completely bailed.
My VDS is apparently in Norfolk but it's actually at Redbus Interhouse at London Docklands.
Our work servers are based in Manchester but it said they are in Newcastle (about 250 miles out).
I guess dynamic IPs are easier to trace since they'll all be dished out via a large ISP in a certain area.