3 ==============================
4 ip based geographic lookups...
5 ==============================
13 .. contents:: Table of Contents
18 :Packages: GeoIP C API & Library (http://www.maxmind.com/download/geoip/api/c/)
23 mod_geoip is a module for fast ip/location lookups. It uses MaxMind GeoIP /
25 If the ip was found in the database the module sets the appropriate
26 environments variables to the request, thus making other modules/fcgi be
31 Currently only country/city databases are supported because they have a free
32 version that i can test.
35 ========================
37 mod_geoip uses two configuration options.
39 1) geoip.db-filename = <path to the geoip or geocity database>
40 2) geoip.memory-cache = <enable|disable> : default disabled
42 if enabled, mod_geoip will load the database binary file to
43 memory for very fast lookups. the only penalty is memory usage.
47 mod_geoip will determine the database type automatically so if you enter
48 GeoCity databse path it will load GeoCity Env.
53 Every database sets it's own ENV:
73 GEOIP_CITY_POSTAL_CODE
75 GEOIP_CITY_LONG_LATITUDE
85 when using fastcgi (not only php) you can access mod_geoip env and do as you
86 please. this example just prints all mod_geoip envs to the client, html.
90 geoip.db-filename = "/your-geoip-db-path/GeoCityLite.dat"
91 geoip.memory-cache = "enable"
96 $country_code = $_SERVER['GEOIP_COUNTRY_CODE'];
97 $country_code3 = $_SERVER['GEOIP_COUNTRY_CODE3'];
98 $country_name = $_SERVER['GEOIP_COUNTRY_NAME'];
100 $city_region = $_SERVER['GEOIP_CITY_REGION'];
101 $city_name = $_SERVER['GEOIP_CITY_NAME'];
102 $city_postal_code = $_SERVER['GEOIP_CITY_POSTAL_CODE'];
103 $city_latitude = $_SERVER['GEOIP_CITY_LATITUDE'];
104 $city_long_latitude = $_SERVER['GEOIP_CITY_LONG_LATITUDE'];
105 $city_dma_code = $_SERVER['GEOIP_CITY_DMA_CODE'];
106 $city_area_code = $_SERVER['GEOIP_CITY_AREA_CODE'];
108 echo "<html>\n<body>\n\t<br>\n";
109 echo 'Country Code: ' . $country_code . '<br>';
110 echo 'Country Code 3: ' . $country_code3 . '<br>';
111 echo 'Country Name: ' . $country_name . '<br>';
113 echo 'City Region: ' . $city_region . '<br>';
114 echo 'City Name: ' . $city_name . '<br>';
115 echo 'City Postal Code: ' . $city_postal_code . '<br>';
116 echo 'City Latitude: ' . $city_latitude . '<br>';
117 echo 'City Long Latitude: ' . $city_long_latitude . '<br>';
118 echo 'City DMA Code: ' . $city_dma_code . '<br>';
119 echo 'City Area Code: ' . $city_area_code . '<br>';
120 echo "</html>\n</body>";
123 country based redirect
124 ----------------------
128 $HTTP["host"] =~ "www.domain.com" {
129 url.rewrite = ( "" => "/redirect.php")
135 $country_code = $_SERVER['GEOIP_COUNTRY_CODE'];
136 header ('Location: http://' . $country_code . '.domain.com/');
141 Currently it is not possible to redirect based on mod_geoip directly in
142 lighttpd config file. But i believe with the relase of lighttpd mod_magnet
143 it would be. (mod_magnet will be available in lighttpd 1.4.12+)
147 mod_geoip.c (http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.c)