Jump to content

Geo-Location by IP


gerkintrigg

Recommended Posts

Hello.

 

I downloaded the Max Mind database and am trying to use a simple PHP MySQL lookup to find the location of an IP address.

 

I think  I may be doing something wrong with the code because it keeps coming up with "United States" even though I'm testing it with UK IPs. Here's my code:

 

<?php

$root='';

//include the database:

include $root.'includes/db.php';

 

// IP address

$code = '81.17.79.2';

 

//get where the IP relates to:

$q="SELECT `friendly_country` FROM `geo_locator` WHERE '$code' BETWEEN `ip_1` AND `ip_2`;";

$sql=mysql_query($q);

$r=mysql_fetch_array($sql);

 

echo 'IP '. $code. " mapped to: " . $r['friendly_country'];

 

?>

Link to comment
https://forums.phpfreaks.com/topic/174775-geo-location-by-ip/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.