Hi all,
We’re using “GeoIP (Apache)” to track visitor locations, but we noticed it wasn’t tracking IPv6 traffic. That’s a hefty part of our client base, so we wrote the following patch to correct it. I can’t find how to submit a patch to a plugin - would someone be able to point me in the right direction?
Thanks.
piwik/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php
@@ -95,6 +95,8 @@
foreach (self::$geoIpServerVars as $resultKey => $geoipVarName) {
if (!empty($_SERVER[$geoipVarName])) {
$result[$resultKey] = $_SERVER[$geoipVarName];
+ }elseif (!empty($_SERVER[$geoipVarName.'_V6'])) {
+ $result[$resultKey] = $_SERVER[$geoipVarName.'_V6'];
}
}
foreach (self::$geoIpUtfServerVars as $resultKey => $geoipVarName) {
@@ -150,7 +152,8 @@
}
$available = !empty($_SERVER[self::TEST_SERVER_VAR])
- || !empty($_SERVER[self::TEST_SERVER_VAR_ALT]);
+ || !empty($_SERVER[self::TEST_SERVER_VAR_ALT])
+ || !empty($_SERVER[self::TEST_SERVER_VAR_ALT.'+_V6']);
if ($available) {
return true;
@@ -180,6 +183,7 @@
{
if (empty($_SERVER[self::TEST_SERVER_VAR])
&& empty($_SERVER[self::TEST_SERVER_VAR_ALT])
+ && empty($_SERVER[self::TEST_SERVER_VAR_ALT.'_V6'])
) {
return Piwik::translate("UserCountry_CannotFindGeoIPServerVar", self::TEST_SERVER_VAR . ' $_SERVER');
}
IPv4 tracking depends on:
- GEOIP_ADDR
- GEOIP_CONTINENT_CODE
- GEOIP_COUNTRY_CODE
- GEOIP_COUNTRY_NAME
And IPv6 depends on:
GEOIP_ADDR
GEOIP_CONTINENT_CODE_V6
GEOIP_COUNTRY_CODE_V6
GEOIP_COUNTRY_NAME_V6
The code above in the latter two snippets, checks for existence of the corresponding V6 server variables.
In the first, if it has not found IPv4 information, it will instead append _V6 to the variable names, and store any of those in the result hash if they exist.