كود PHP:
	
<?php 
function getALLfromIP($addr,$db) { 
  // this sprintf() wrapper is needed, because the PHP long is signed by default 
  $ipnum = sprintf("%u", ip2long($addr)); 
  $query = "SELECT cc, cn FROM ip NATURAL JOIN cc WHERE ${ipnum} BETWEEN start AND end"; 
  $result = mysql_query($query, $db); 
  if((! $result) or mysql_numrows($result) < 1) { 
    //exit("mysql_query returned nothing: ".(mysql_error()?mysql_error():$query)); 
    return false; 
  } 
  return mysql_fetch_array($result); 
} 
function getCCfromIP($addr,$db) { 
  $data = getALLfromIP($addr,$db); 
  if($data) return $data['cc']; 
  return false; 
} 
function getCOUNTRYfromIP($addr,$db) { 
  $data = getALLfromIP($addr,$db); 
  if($data) return $data['cn']; 
  return false; 
} 
function getCCfromNAME($name,$db) { 
  $addr = gethostbyname($name); 
  return getCCfromIP($addr,$db); 
} 
function getCOUNTRYfromNAME($name,$db) { 
  $addr = gethostbyname($name); 
  return getCOUNTRYfromIP($addr,$db); 
} 
$db = mysql_connect("localhost","username","password") or die ("mysql_connect() failed: " . mysql_error()); 
mysql_select_db("geoip",$db) or die ("mysql_select_db() failed: " . mysql_error()); 
$remote = $_SERVER['REMOTE_ADDR']; 
echo "<p>".getCCfromIP($remote,$db)."</p>\n"; 
echo "<p>".getCOUNTRYfromIP($remote,$db)."</p>\n"; 
// مع تغيير اعدادات قاعدة البيانات  
?>
  
						
					
مواقع النشر (المفضلة)