<?
@session_start();
define("FromIndex", "true");
require_once("functions.php");
require_once("config.php");
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ip_address = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ip_address = getenv(REMOTE_ADDR);
}
function Dot2LongIP ($IPaddr) {
if ($IPaddr == "")
{
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
$ipno = Dot2LongIP($ip_address);
$country = $db->execute("SELECT * FROM `ipcountry` WHERE $ipno BETWEEN begin_num AND end_num LIMIT 0, 30 ");
echo $country['name']; ?> <br /> <? echo $ip_address;?>
The code above gets a users ip then splits it into a ip number. Then i use the sql query to look up what country the visitor comes from.. This is the line im having trouble with
$country = $db->execute("SELECT * FROM `ipcountry` WHERE $ipno BETWEEN begin_num AND end_num LIMIT 0, 30 ");
Btw this works perfect in phpmyadmin