Is there a way to do a PHP If statement based on the persons location?
My problem comes down to Amazon Affiliate links. The link to buy a DVD on Amazon.co.uk is diff
You're going to have to use the visitor's IP address to lookup their physical location. Apart from using the GeoIP extension for PHP (as stewe pointed out), there are two ways of doing this:
The easy way
Use an external service like http://www.hostip.info
With your own MySQL data
1.) Retrieve the visitors' IP address:
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip_address = getenv('HTTP_X_FORWARDED_FOR');
}
else
{
$ip_address = getenv('REMOTE_ADDR');
}
2.) Convert the visitor's IP address to an IP Number:
$ips = explode(".",$ip_address);
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
3.) Locate the IP Number from your database which you can download here. For example: the IP Address 202.186.13.4 converts to IP Number 3401190660. It is between the beginning and the ending of the following IP numbers:
Beginning_IP | End_IP | Country | ISO
-------------+-------------+----------+----
3401056256 | 3401400319 | MALAYSIA | MY