View Full Version : Geo targetting page of my site

08-02-2009, 09:31 PM
Well actually just a few links, I would like people only in one country to see these links, not the rest of the world - what is the bes way of doing this?


08-02-2009, 09:36 PM
Is there any reason for this? You can really, really annoy people by doing that kind of thing (I'm looking at you, Hulu.)

08-03-2009, 12:33 PM
Yes, the links take the user to a shop where we sell products only allowed to be sold in our home country :)

08-03-2009, 12:36 PM
A quick google found this DB (http://www.ip2location.com/ip-country.aspx)

08-03-2009, 05:02 PM
using PHP this will work. Maybe not 100% fool proof but it's worth a shot.

$Users_IP_address = $_SERVER["REMOTE_ADDR"];

function countryFromIP($ipAddr)
//Originally developed by Roshan Bhattarai http://roshanbh.com.np
//Modified by Alan Jackson http://tugbucket.net

ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
$xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);
return $ipDetail;


$countryCode = array("UK", "GB"); // slap in your country codes in theis array

if (in_array($IPDetail['country_code'], $countryCode)) {
echo "UK based links here.";
else {
echo "Non UK based links here.";

08-03-2009, 10:48 PM
Also, make sure you allow a manual override in case it screws up.