Пример #1
0
/**
 * Sometimes we can only see an local IP adress (local development environment.)
 * In this case we need to ask an internet server which IP adress our internet connection has.
 * 
 * @return string The detected IP Adress. If none is found, '0.0.0.0' is returned instead.
 */
function geoip_detect_get_external_ip_adress()
{
    static $ip_cache = null;
    if (!is_null($ip_cache)) {
        return apply_filters('geoip_detect_get_external_ip_adress', $ip_cache);
    }
    $ip_cache = _geoip_detect_get_external_ip_adress_without_cache();
    $ip_cache = apply_filters('geoip_detect_get_external_ip_adress', $ip_cache);
    return $ip_cache;
}
 function testExternalIpProviders()
 {
     remove_filter('pre_transient_geoip_detect_external_ip', array($this, 'filter_set_external_ip'), 101);
     add_filter('geiop_detect_ipservices', array($this, 'externalIpProvidersFilter'), 101);
     $this->providers = null;
     do {
         $ip = _geoip_detect_get_external_ip_adress_without_cache();
         $this->assertNotEquals('0.0.0.0', $ip, 'Provider did not work: ' . $this->currentProvider);
     } while (count($this->providers));
 }
Пример #3
0
 function testExternalIp()
 {
     $ip = _geoip_detect_get_external_ip_adress_without_cache();
     $this->assertNotEquals('0.0.0.0', $ip);
 }
Пример #4
0
/**
 * Sometimes we can only see an local IP adress (local development environment.)
 * In this case we need to ask an internet server which IP adress our internet connection has.
 * 
 * @param boolean $unfiltered If true, do not check the options for an external adress. (Default: false)
 * @return string The detected IPv4 Adress. If none is found, '0.0.0.0' is returned instead.
 * 
 * @since 2.0.0
 * @since 2.4.3 Reading option 'external_ip' first.
 * @since 2.5.2 New param $unfiltered that can bypass the option.
 */
function geoip_detect2_get_external_ip_adress($unfiltered = false)
{
    $ip_cache = '';
    if (!$unfiltered) {
        $ip_cache = get_option('geoip-detect-external_ip');
    }
    if (!$ip_cache) {
        $ip_cache = get_transient('geoip_detect_external_ip');
    }
    if (!$ip_cache) {
        $ip_cache = _geoip_detect_get_external_ip_adress_without_cache();
        set_transient('geoip_detect_external_ip', $ip_cache, GEOIP_DETECT_IP_CACHE_TIME);
    }
    $ip_cache = apply_filters('geoip_detect_get_external_ip_adress', $ip_cache);
    return $ip_cache;
}