http://sourceforge.net/projects/phpwhois/
<?php
// Include PHPWhois libs
include('phpwhois/whois.main.php');
include('phpwhois/whois.ip.lib.php');
include('phpwhois/whois.ip.php');
// Figure out the client's IP
$ip = $_SERVER['REMOTE_ADDR'];
// Perform the IP whois query
$whois = new Whois();
$result = $whois->Lookup($ip,false);
$country_code = $result['regrinfo']['owner']['address']['country'];
echo $country_code; // Will output 'CA', 'US' or wherever visitor is from
?>
<?php
// Include PHPWhois libs
include('phpwhois/whois.main.php');
include('phpwhois/whois.ip.lib.php');
include('phpwhois/whois.ip.php');
// Figure out the client's IP
$ip = $_SERVER['REMOTE_ADDR'];
// Perform the IP whois query
$whois = new Whois();
$result = $whois->Lookup($ip,false);
// Parse the country code
$country_code = $result['regrinfo']['owner']['address']['country'];
$country_code = $result['regrinfo']['owner']['address'];
if (strlen($country_code) != 2)
{
$country_code = $result['regrinfo']['owner']['address']['country'];
if (strlen($country_code) != 2)
{
$country_code = $result['regrinfo']['owner']['address'][1];
if (strlen($country_code) != 2)
{
$country_code = $result['regrinfo']['owner']['address'][2];
if (strlen($country_code) != 2)
{
$country_code = $result['regrinfo']['network']['country'];
}
}
}
}
echo $country_code; // Will output 'CA', 'US' or wherever visitor is from
?>
Mucho Grasias!!!
I as just looking at the maxmind site, however I dont see where they offer the free DB. could you point me in the right direction.
Thanks
http://www.spoffle.com/technical/geotarget-wordpress-plugin/
If your doing this to try to increase conversions etc you should really look into the paid version of this database as it is far more accurate (take this from someone who has compared the 2 and owns it)