Web Hosting Talk







View Full Version : IP address location lookup?


UH-Matt
04-26-2005, 12:24 PM
Anybody know how to take an IP in PHP and lookup its location (city, country)?

whois.sc does it, and i'd like to have this added to our ordering process.

We already have the IP being logged to $ip but it would be nice to take this and lookup the location for comparing with address of card holder?

Thanks for any help in advance...

Insert_Name_Here
04-26-2005, 12:46 PM
here is one for ip to country

http://www.phpclasses.org/browse/package/1477.html

azizny
04-26-2005, 02:13 PM
I am starting to hate phpclasses.org...

too much advertising, login and sloww...

I personally use a database version:


<?
function check_country($ip){
$ip = sprintf("%u", ip2long($ip));
$country = 'other';

$check_country = @mysql_query("SELECT `country`,`a2`,`a3`,`number` FROM `country_ip_list` WHERE `ipfrom` <= '$ip' and `ipto` >= '$ip' LIMIT 0, 1");

if($get_country = @mysql_fetch_row($check_country)){
$country = $get_country[0];
}
return $country;
}
?>


I'll try to attach the sql file, otherwise I will post it as an online lesson :p (file too big)

pm me and i'll email it to you throu yousendit.com

Peace,

azizny
04-26-2005, 03:15 PM
Anyone else interested in downloading the database file:

http://s25.yousendit.com/d.aspx?id=3NRQ3EH4UT0CD1Q07OIH3RJK60

Peace,

Jon69
04-26-2005, 04:54 PM
http://www.ip2nation.com/ for the DB and sample scripts.

If you just want to display a users country on your site without the need to set up the DB tables, check out http://www.ipcatch.com/webmasters.php

UH-Matt
04-26-2005, 05:01 PM
Thanks for all the help guys. This is all I needed!

dalnet2
04-29-2005, 12:34 PM
ip2nation.com
But available in certain country only

dalnet2
04-29-2005, 12:37 PM
visit dnstuff.com

Rob83
04-29-2005, 03:27 PM
I would only try to get the country (which is easy), getting the city isn't always accurate as the IP may be registered elsewhere.

VolkNet
04-29-2005, 04:25 PM
Thanks azizny! :-D Thats awesome.

dumisani
04-30-2005, 04:06 PM
Works like a charm

legacy616
05-16-2005, 08:46 PM
Is there any way to lookup the region like west coast / east coast... or maybe the timezone?

azizny
05-16-2005, 09:31 PM
Originally posted by legacy616
Is there any way to lookup the region like west coast / east coast... or maybe the timezone?

for the us or whole world?

Peace,

legacy616
05-16-2005, 09:39 PM
just the United States... we have a regional website.. we would like to figure out who is outside of the Los Angeles/California area

azizny
05-16-2005, 11:34 PM
ok...

an open source databse with contains the long/lats:

http://sourceforge.net/projects/zips/

Peace,

error404
05-17-2005, 02:07 AM
http://www.maxmind.com/app/php