Re: Finding a visitor's location

From: Date: Mon, 23 Oct 2006 10:22:23 +0000
Subject: Re: Finding a visitor's location
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-243463@lists.php.net to get a copy of this message
On Mon, 23 Oct 2006 19:00:08 +1000, Chris wrote: > John Messam wrote: >> Hello, I am trying to find out the country and possibly the city where the >> visitors to my site are coming from. I can capture the IP address but how >> do I translate that to a specific locale. Is there a way to do it or do I >> have to ask them and map the info myself. Thank you for you help. This list >> is a very useful tool. > > Search for "geo-ip database" or "ip to country" or some such variant in > a search engine. To quickly do a relatively simple check (do not expect high success rate, but it doesn't require you to download/purchase databases) is do a reverse-DNS lookup (gethostbyaddr) on $_SERVER['REMOTE_ADDR'], check if it's the same IP address (failed), if not you've got yourself a hostname. Grab the last piece after the dot (strrchr), and you've got the TLD... Although it includes TLD's like com, net, org, edu and such it also includes countries.

« previous php.general (#243463) next »