Hello,

Nick Wilson wrote:
> What functions do I need to be looking at if I want to determine from
> what country a visitor is from?
> 
> Is this problematical, I look at my logs shows that not all visitors
> form .dk have that at the end of the refferer string...

You may use GetEnv("REMOTE_HOST") to return the user address domain. If
this is not resolved, you may try gethostbyaddr(GetEnv("REMOTE_ADDR")) .

With the domain, you may pick the top level domain (TLD) part just
keeping the domain string after the last dot. If the TLD has 2
characters it is the country code.

If this fails, you may want to resort to a IP address location service
like NetGeo.

If you do not want to reinvent the wheel, you may want to try to use
this ready to use PHP class that does that for you to get not only the
country, but also the location and coordinates (latitude and longitude).

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


Here you may find an application of this class to rank all the countries
from where the users log in this site:

http://www.phpclasses.org/browse.html/statistics/statistics.html#user-countries


An even cooler application of this class is this page for the users to
pick the mirror site that is closer from the user computer network with
distances in Kilometers computed by the same class:

http://www.phpclasses.org/mirrors.html?closest=1

Regards,
Manuel Lemos

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to