Jump to content

MaxMind GeoIP City on MySQL database has stopped working?


MrTIMarshall

Recommended Posts

Hello,

 

I was recently receiving help from a member of PHP Freaks, however they have stopped communication for an unknown reason and therefore I am unable to get hold of them, They helped me set up the free version of the MaxMind GeoIP City database on my 1and1 MySQL Database where I have three tables. These are; blocks, country and location.

 

He also send PHP code to read the database:

<?php

include("db_geo.php");
$db = new mysqli($hostname,$username,$password,$database);

function query2HTMLtable($db, $sql)
{
    $output = "<table border='1'>\n";
    // Query the database
    $result = $db->query($sql);
    // check for errors
    if (!$result) return ("$db->error");
    // get the first row and display headings
    $row = $result->fetch_assoc();
    $output .= "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n";
    // display the data
    do {
        $output .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n";
    } while ($row = $result->fetch_assoc());
    $output .= "</table>\n";
    return $output;
}
 
function ip2integer ($ip)
{
    return sprintf('%u', ip2long($ip));
}
 
$ip = $_SERVER[REMOTE_ADDR];
$ipInt = ip2integer($ip); // convert to integer to use in query
 
$sql = "SELECT c.name as country, l.city, l.latitude, l.longitude
		FROM blocks b
		INNER JOIN location l USING (locId)
		INNER JOIN country c ON l.country = c.code
		WHERE $ipInt BETWEEN b.startIpNum AND endIpNum";

$result = $db->query($sql);
	if ($result->num_rows > 0) {
		list ($country, $city, $latitude, $longitude) = $result->fetch_row();
	}
	else $country = $city = $latitude = $longitude = null;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
<h1>Test Info Below</h1>
<?php
echo "Your country is $country<br />";
echo "Your city is $city<br />";
echo "Your Latitude is $latitude<br />";
echo "Your longitude is $longitude";
?>
</body>
</html>

 

...Which used to result in the below:

 

 

Test Info BelowYour country is United Kingdom
Your city is Bury
Your Latitude is 53.6
Your longitude is -2.3

 

I have not changed anything to my knowledge on this page, the inc database page or the database, however, just in case I have maybe someone and see what is wrong. If anyone is using 1and1, I am  on a Linux account, I am unsure if 1and1 have changed anything themselves.

 

The page: http://sunlightgardenservices.co.uk/whereareyou.php

 

Thank you in advanced for any help and/or advice in fixing this page.

 

Best Regards,

Tim

Link to comment
Share on other sites

I have just clicked on the link you provided and got

 

 

So can you explain the problem?

 

The information I see is;

 

Test Info BelowYour country is 

Your city is 

Your Latitude is 

Your longitude is

 

When previously it was pulling up

 

Your country is United Kingdom

Your city is Bury

Your Latitude is 53.6

Your longitude is -2.3

 

Thank you for your response.

 

Best Regards,

Tim

Link to comment
Share on other sites

I would say most likely the problem is just that the IP you are using to access the site at the time when it is blank does not exist in the version of the database you have. Have you tried looking up the IP manually using something like PHPMyAdmin to see if it exists?

Link to comment
Share on other sites

Ah yes, I do not appear to be in the database version I currently have. The results for me are that nothing was found. I went on the testing page at my dads today, whom lives around the corner from us and it pulled up data.

 

I think my IP address changes every time our router is restarted, of which we do every night as we turn it of via the wall.

 

Best Regards,

Tim

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.