Comments on Installing mod_geoip for Apache2 On Ubuntu 12.04

Installing mod_geoip for Apache2 On Ubuntu 12.04 This guide explains how to set up mod_geoip with Apache2 on an Ubuntu 12.04 system. mod_geoip looks up the IP address of the client end user. This allows you to redirect or block users based on their country. You can also use this technology for your OpenX (formerly known as OpenAds or phpAdsNew) ad server to allow geo targeting.

2 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By:

Thanks for the great howto. I ran into an issue with the testing method above using apache_note.

No output but an error in the log

mod_fcgid: stderr: PHP Fatal error: Call to undefined function apache_note()

From what I understand it is due to a server configuration using either suphp or running Apache as cgi.

I verified in phpinfo that despite the error Geoip is working fine. To get the output I just had to access the Apache environment variables.

 

<?php
// Example use of getenv()
$country = getenv('GEOIP_COUNTRY_NAME');
print "Country: " . $country;
// Or simply use a Superglobal ($_SERVER or $_ENV)
$ccode = $_SERVER['GEOIP_COUNTRY_CODE'];
print "<br>Country Code: " . $ccode;
?>

http://www.php.net/manual/en/function.apache-getenv.php

By: Ben Lacey

The module creates server variables that you can use in your PHP files so instead of using apache_note() use the following instead:

<?php
echo "Country Name: " . $_SERVER["GEOIP_COUNTRY_NAME"];
echo "<br/>Country Code: " . $_SERVER["GEOIP_COUNTRY_CODE"];
echo "<br>Continent: " . $_SERVER["GEOIP_CONTINENT_CODE"];
?>

Have a look here: http://dev.maxmind.com/geoip/legacy/mod_geoip2/ at "Output Variables" - these can all be used using $_SERVER['output-variable-here'] syntax.