RE: [PHP] Personal statics
| From: | Emil Rasmussen | Date: | Sun, 07 Jan 2001 13:35:20 +0000 |
| Subject: | RE: [PHP] Personal statics | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-33089@lists.php.net to get a copy of this message | ||
Hi
>
> I know to obtain the ip of a visitor and the name of the
> host. But i
> want to obtain the country of this ip.
>
> How can do it?
>
$host_address = gethostbyaddr($REMOTE_ADDR);
if (strpos($host_address,".")) {
$country = rtrim(substr($host_address,strrpos($host_address,".") +
1,3));
}
This will get you the top level domain, and then you have to match it
against a list af country names.
Something like this:
switch ($country) {
case "com":
$country = ".com US/int";
break;
case "net":
$country = ".net US/int";
break;
case "ca":
$country = "Canada";
break;
case "uk":
$country = "England";
break;
case "org":
$country = ".org US/int";
break;
case "":
$country = "Unkonw";
break;
}
:: Emil
---
Emil Rasmussen
http://www.noget.net