views:

119

answers:

6

What are the location detecting tecniques for IP adresses?
I know to look at the
$_SERVER['HTTP_ACCEPT_LANGUAGE'] (not accurate but mostly useful to detect location, for example if an IP range's users set French to their browser then it means that this range) belongs to France
and
gethostbyaddr($_SERVER['REMOTE_ADDR']) (to look country code top-level domain)
then may be to whois gethostbyaddr($_SERVER['REMOTE_ADDR'])
sometimes:
$HTTP_USER_AGENT (Firefox's user agent string has language code, not accurate but mostly can be used to detect the location)

Also I know how to get the time zone but it does not work in the new browsers. Moreover there is css issue that detects visitor's history, it can be used to see what google and wikipedia pages he/she has visited (google.co.uk, google.com.tr)

But what about cities?

+1  A: 

DID you try html5 geolocation api? http://www.w3.org/TR/geolocation-API/

manugupt1
I know it but I do not want to disturbe the visitors.
ilhan
+1  A: 

There are several possibilities outlined here: Entering The Wonderful World of Geo Location

Giorgi
+2  A: 

You can't do this without a database that maps IP addresses to cities/countries/providers. There are commercial offerings such as ip2location that you could use. AFAIK there is no free alternative though, as maintaining such a IP database is quite a lot of work.

Update: There are several things that allow you to create such a db, if you invest enough time:

  1. Use the databases provided by regional and local registries to find an IP's owner.
  2. Many ISPs use a naming schema that allows you to locate the user. Sometimes you can even read the city name in plain text if you do a reverse-DNS lookup. Sometimes it is more cryptic. For example I currently have p5dcf6c4a.dip.t-dialin.net , and I have no idea that the naming scheme is..
  3. Use a traceroute. If you can't identify the location of a user, you can still find out the location of its uplink
Tim Jansen
Yes, I know them but I want to learn how do they make their own database.
ilhan
+1  A: 

There are databases (some of them are free of charge) which can be used to convert IP's into Cities:

eg: http://www.maxmind.com/app/geolitecity

iNPUTmice
I know it, it is very useful for big countries but it is not accurate for Bulgaria. All my visitors are from south east Bulgaria, but it shows them like they are from central west (capital city).
ilhan
A: 

One way in which these databases are compiled is from whois information. For example, to determine the location of 69.59.196.211:

fmark@home:~$ host 69.59.196.211 211.196.59.69.in-addr.arpa domain name pointer stackoverflow.com. fmark@home:~$ whois stackoverflow.com

Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered with many different competing registrars.

 <SNIP>

> Registrant: stackoverflow.com llc
410 Clayton Ave El Cerrito, California 94530 United States

 <SNIP>

Obviously this isn't hugely accurate, so more sophisticated techniques are allegedly used.

fmark
A: 

You can get useful geographical location information in IP2Location database which is converting the IP address into country, region, city, etc

hexahow