How to fix this MaxMind GeoIP redirection issue?

552 Views Asked by At

On my old web host, there was a specific page on my site (not the homepage) set up to redirect users based on their country, as determined by their IP using the MaxMind database. The redirect code was working fine until I migrated to a new webhost.

The problem was that the new host didn't have the MaxMind db installed. But even after I installed it on my VPS, I'm still getting the following error message whenever I test to see if the redirecting is working: "Fatal error: Call to undefined function geoip_record_by_name() in /my/file/path on line 2"

Here's the code in the redirect file:

<?PHP
$ipinfo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
$country = $ipinfo['geoip_country_code'];

switch($country) { XXX
}
?>

Does anyone have any idea what I'm doing wrong?

1

There are 1 best solutions below

0
On

Your previous web host likely had the GeoIP PECL extension installed. If you install that and the GeoIP City database at your new web host, the above code should work.

If you are unable to install extensions, you could try the pure PHP API. You will have to make some changes to your code though, as the API differs slightly from the extension.