Generalissimo
03-11-2007, 03:51 PM
I've bought a copy of MaxMind's db,
and now I'm trying to create a page that I will link an advertisement to that will then go to one of three urls based on what country the user is from (UK, USA or any other country)...
The code does not seem to work as it directs me to the international URL when I'm from the UK... Does anyone have any idea what I've done wrong?
<html>
<head>
<meta http-equiv="refresh" content="0;url=<?
$DatabaseServer = "localhost";
$Username = "user";
$Password = "pass";
$DatabaseName = "db";
$link = mysql_connect($DatabaseServer, $Username, $Password) or die('Could not connect: ' . mysql_error());
mysql_select_db($DatabaseName) or die('Could not select database');
$IP = $_SERVER["REMOTE_ADDR"]; //Get the IP address
$res = mysql_query("SELECT country_code2,country_name FROM IPCountries WHERE IP_FROM<=inet_aton('$IP') AND IP_TO>=inet_aton('$IP')");//look up IP address
if($CountryCode == "GB"){
//echo url for United Kingdom
echo "UKURL";
}
if($CountryCode == "US"){
//echo url for USA
echo "USURL";
}
else{
//default international url
echo "INTURL";
}
mysql_close($link); //clean up
?>">;
</head></html>
and now I'm trying to create a page that I will link an advertisement to that will then go to one of three urls based on what country the user is from (UK, USA or any other country)...
The code does not seem to work as it directs me to the international URL when I'm from the UK... Does anyone have any idea what I've done wrong?
<html>
<head>
<meta http-equiv="refresh" content="0;url=<?
$DatabaseServer = "localhost";
$Username = "user";
$Password = "pass";
$DatabaseName = "db";
$link = mysql_connect($DatabaseServer, $Username, $Password) or die('Could not connect: ' . mysql_error());
mysql_select_db($DatabaseName) or die('Could not select database');
$IP = $_SERVER["REMOTE_ADDR"]; //Get the IP address
$res = mysql_query("SELECT country_code2,country_name FROM IPCountries WHERE IP_FROM<=inet_aton('$IP') AND IP_TO>=inet_aton('$IP')");//look up IP address
if($CountryCode == "GB"){
//echo url for United Kingdom
echo "UKURL";
}
if($CountryCode == "US"){
//echo url for USA
echo "USURL";
}
else{
//default international url
echo "INTURL";
}
mysql_close($link); //clean up
?>">;
</head></html>