1 |
<?php |
2 |
/* This file is part of BBClone (A PHP based Web Counter on Steroids) |
3 |
* |
4 |
* CVS FILE $$Id: ext_lookup_geoip.php,v 1.11 2011/12/30 23:03:39 joku Exp $$ |
5 |
* |
6 |
* Copyright (C) 2001-2012, the BBClone Team (see doc/authors.txt for details) |
7 |
* |
8 |
* This program is free software: you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* See doc/copying.txt for details |
19 |
*/ |
20 |
|
21 |
///////////////////////////////////////// |
22 |
// Plug-in: Extension look-up by GeoIP // |
23 |
///////////////////////////////////////// |
24 |
|
25 |
function bbc_extension_plugin($host, $addr) { |
26 |
global $BBC_GEOIP_PATH, $gi; |
27 |
|
28 |
// First of all let's check if the include file exists |
29 |
if (!@file_exists($BBC_GEOIP_PATH.'geoip.inc')) { |
30 |
bbc_msg('Missing geoip installation'); |
31 |
} |
32 |
include_once($BBC_GEOIP_PATH.'geoip.inc'); |
33 |
|
34 |
// Bail out if the file exists but does not seem to be geoip |
35 |
if (!function_exists('geoip_open')) { |
36 |
return ""; |
37 |
} |
38 |
|
39 |
if (preg_match('/^.{1,4}:/',$addr)) { |
40 |
$gi = geoip_open($BBC_GEOIP_PATH ."GeoIPv6.dat",GEOIP_STANDARD); |
41 |
$addr = geoip_country_code_by_addr_v6($gi, $addr); |
42 |
} else { |
43 |
$gi = geoip_open($BBC_GEOIP_PATH ."GeoIP.dat",GEOIP_STANDARD); |
44 |
$addr = geoip_country_code_by_addr($gi, $addr); |
45 |
} |
46 |
geoip_close($gi); |
47 |
return strtolower($addr); |
48 |
} |
49 |
?> |