How to get location from ip address. I want to retrieve information like city, state, country of my visitors from their ip address, so that i can customize my web page. I am using php/mysql/javascript for server and client scripting. Is their a way to do the above.
You need to use an external service... such as http://www.hostip.info/ if you google search for "geo-ip" you can get more results.
The Host-IP API is HTTP based so you can use it either in PHP or JavaScript depending on your needs.
Look at the API from hostip.info - it provides lots of information.
Example in php:>
$data = file_get_contents("http://api.hostip.info/country.php?ip=12.215.42.19");
//$data = "US"
$data = file_get_contents("http://api.hostip.info/?ip=12.215.42.19");
//$data = lots of xml with country, lat, long, city, etc...
If you trust hostip.info, it seems to be a very useful API.
Assuming you want to do it yourself and not rely upon other providers, IP2Nation provides a MySQL database of the mappings which are updated as the regional registries change things around.
This is pretty much a duplicate of http://stackoverflow.com/questions/348614/how-do-i-determine-a-zip-code-and-city-from-an-ip-address.
I'll make the same answer I did here as the service is available for PHP also:
I like the free GeoLite City from Maxmind which works for most applications and from which you can upgrade to a paying version if it's not precise enough. There is a PHP API included, as well as for other languages. And if you are running Lighttpd as a webserver, you can even use a module to get the information in the SERVER variable for every visitor if that's what you need.
I should add there is also a free Geolite Country (which would be faster if you don't need to pinpoint the city the IP is from) and Geolite ASN (if you want to know who owns the IP) and that finally all these are downloadable on your own server, are updated every month and are pretty quick to lookup with the provided APIs as they state "thousands of lookups per second".