i need somebody to help me with a little issue please. i have a script that connects to a database and matches their ip address then displays the result in the web browser, here is the code for that - <?php $server = 'localhost'; // MySQL hostname $username = 'username'; // MySQL username $password = 'password'; // MySQL password $dbname = 'dbname'; // MySQL db name $db = mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = 'SELECT code FROM ip2nationCountries c, ip2nation i WHERE i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1'; list($countryName) = mysql_fetch_row(mysql_query($sql)); // Output Country Code echo $countryName; ?> What i want is a query that will display page1.php to anyone from the USA and page2.php to anyone from anywhere else in the world. The database im using is here i will pay somebody who posts the first working query
$sql = 'SELECT code FROM ip2nationCountries c, ip2nation i WHERE i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") AND c.code = 'us' ORDER BY i.ip DESC LIMIT 0,1'; $sql = 'SELECT code FROM ip2nationCountries c, ip2nation i WHERE i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") AND c.code != 'us' ORDER BY i.ip DESC LIMIT 0,1'; Just from top of the head, didn't test it.
it didnt work mate, somebody suggested this, but that didnt work either <?php $server = 'localhost'; // MySQL hostname $username = 'username'; // MySQL username $password = 'password'; // MySQL password $dbname = 'dbname'; // MySQL db name $db = mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = 'SELECT country_code FROM ip_group_country WHERE ip_start <=INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") ORDER BY ip_start DESC LIMIT 0,1'; list($CountryCode) = mysql_fetch_row(mysql_query($sql)); ?> <? echo $CountryCode; ?>
Try this <?php $server = 'localhost'; // MySQL hostname $username = 'username'; // MySQL username $password = 'password'; // MySQL password $dbname = 'dbname'; // MySQL db name $db = mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = "SELECT `country_code` FROM `ip_group_country` WHERE `ip_start` <=INET_ATON('".$_SERVER['REMOTE_ADDR']."') ORDER BY `ip_start` DESC LIMIT 1'; $query=mysql_query($sql)or trigger_error(mysql_error()); list($CountryCode) = mysql_fetch_row($query); ?> <? echo $CountryCode; ?> PHP: If it doesn't work, it at least gives you some feedback about what exactly is wrong
The thing is, you don't only need query modification, but php code modification as well. You can find fully working example here, don't know if it already was there or it just got added: http://www.ip2nation.com/ip2nation/Sample_Scripts/Country_Based_Redirect