- next is 1.4.56
[lighttpd.git] / doc / geoip.txt
blob99b0ed096e5cba36525000f0ca9a777b4f5e98e9
1 {{{
2 #!rst
3 ==============================
4 ip based geographic lookups...
5 ==============================
7 -----------------
8 Module: mod_geoip
9 -----------------
13 .. contents:: Table of Contents
15 Requirements
16 ============
18 :Packages: GeoIP C API & Library (http://www.maxmind.com/download/geoip/api/c/)
20 Overview
21 ========
23 mod_geoip is a module for fast ip/location lookups. It uses MaxMind GeoIP /
24 GeoCity databases.
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
27 informed.
29 .. note::
31   Currently only country/city databases are supported because they have a free
32   version that i can test.
34 Configuration Options
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.
45 .. note::
47  mod_geoip will determine the database type automatically so if you enter
48  GeoCity databse path it will load GeoCity Env.
50 Environment
51 ===========
53 Every database sets it's own ENV:
55 GeoIP (Country):
56 ----------------
60  GEOIP_COUNTRY_CODE
61  GEOIP_COUNTRY_CODE3
62  GEOIP_COUNTRY_NAME
64 GeoCity:
65 --------
69  GEOIP_COUNTRY_CODE
70  GEOIP_COUNTRY_CODE3
71  GEOIP_COUNTRY_NAME
72  GEOIP_CITY_NAME
73  GEOIP_CITY_POSTAL_CODE
74  GEOIP_CITY_LATITUDE
75  GEOIP_CITY_LONG_LATITUDE
76  GEOIP_CITY_DMA_CODE
77  GEOIP_CITY_AREA_CODE
79 Examples
80 ========
82 mod_geoip + php
83 ---------------
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.
88 Config-file ::
90  geoip.db-filename = "/your-geoip-db-path/GeoCityLite.dat"
91  geoip.memory-cache = "enable"
93 index.php ::
95  <?php
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>';
112          echo '<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>";
121  ?>
123 country based redirect
124 ----------------------
126 Config-file ::
128  $HTTP["host"] =~ "www.domain.com" {
129      url.rewrite = ( "" => "/redirect.php")
132 redirect.php ::
134  <?php
135         $country_code = $_SERVER['GEOIP_COUNTRY_CODE'];
136         header ('Location: http://' . $country_code . '.domain.com/');
137  ?>
139 .. note::
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+)
145 Downloads
146 =========
147 mod_geoip.c (http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.c)