简体   繁体   English

Apache mod_geoip - 如果国家/大陆未知,$ _SERVER ['GEOIP_COUNTRY_CODE'] / $ _SERVER ['GEOIP_CONTINENT_CODE']会有什么相同的?

[英]Apache mod_geoip - What will $_SERVER['GEOIP_COUNTRY_CODE'] / $_SERVER['GEOIP_CONTINENT_CODE'] equal if country / continent is unknown?

We use apaches mod_geoip AND php's geoip.so modules to detect the country / continent a user is visiting from. 我们使用apach mod_geoip和php的geoip.so模块来检测用户正在访问的国家/地区。

Initially we just used PHP's, but a few months ago we began using geoip data within our apache configuration so now we use both. 最初我们只使用PHP,但几个月前我们开始在我们的apache配置中使用geoip数据,所以现在我们使用两者。

This is redundant. 这是多余的。

We are looking at disabling php's geoip.so since we already have the country / continent exposed in $_SERVER['GEOIP_COUNTRY_CODE'] / $_SERVER['GEOIP_CONTINENT_CODE']. 我们正在考虑禁用php的geoip.so,因为我们已经在$ _SERVER ['GEOIP_COUNTRY_CODE'] / $ _SERVER ['GEOIP_CONTINENT_CODE']中公开了country / continent。

Before we do this, we need to know what these 2 will equal IF geoip is unable to detect the location of the user. 在我们这样做之前,我们需要知道这些2将等于IF geoip无法检测到用户的位置。

Previously, on the php end we used something along the lines of: 以前,在php端,我们使用了以下内容:

function geoiplookup($ip){
    if($return=@geoip_country_code_by_name($ip))
        return $return;
    return false;
}

So if geoip_country_code_by_name was unable to retrieve the country code, and thus returned false, we set the script-stored country code to (bool)false. 因此,如果geoip_country_code_by_name无法检索国家/地区代码,从而返回false,我们将脚本存储的国家/地区代码设置为(bool)false。

So, 所以,

When using apache mod_geoip what does geoip set these 2 variables to if it is unable to retrieve the country code? 当使用apache mod_geoip时,如果无法检索国家代码,geoip会将这2个变量设置为什么?

Thanks. 谢谢。

We decided to take a look at the mod_geoip source. 我们决定看一下mod_geoip源码。

From the Changes file: 来自Changes文件:

1.3.3 Aug 13th 2008 1.3.3 2008年8月13日

  • Fix GEOIP_COUNTRY_CODE is not set, when the region database is used and no country is found. 修复当使用区域数据库且未找到国家/地区时,未设置GEOIP_COUNTRY_CODE。 Previously GEOIP_COUNTRY_CODE was set but empty ( Boris Zentner ) 以前GEOIP_COUNTRY_CODE已设置但空(Boris Zentner)

So it would appear that if a country / continent CANNOT be found from the provided IP, GEOIP_COUNTRYC_CODE simply WILL NOT be set. 因此,如果无法从提供的IP中找到国家/大陆,则GEOIP_COUNTRYC_CODE将不会被设置。

Can someone confirm this as this is a fairly vital part of our code base and we need to make sure. 有人可以证实这一点,因为这是我们代码库的一个相当重要的部分,我们需要确保。

We are having a hard time looking thru the C code and finding out exactly what is happening on unknown country. 我们很难通过C代码查看并确切了解未知国家/地区的情况。


From what we can tell, yes, GEOIP_COUNTRY_CODE is only set if the country can be detected. 据我们所知,是的,只有在可以检测到国家时才设置GEOIP_COUNTRY_CODE。

From the mod_geoip source: 来自mod_geoip源:

if (cfg->GeoIPOutput & GEOIP_NOTES) {
    ap_table_set(r->notes, "GEOIP_CONTINENT_CODE", continent_code);
    ap_table_set(r->notes, "GEOIP_COUNTRY_CODE", country_code);
    ap_table_set(r->notes, "GEOIP_COUNTRY_NAME", country_name);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM