/** * Get Geo-Information for the current IP * * @param array(string) $locales List of locale codes to use in name property * from most preferred to least preferred. (Default: Site language, en) * @param array Property names with options. * @param boolean $skipCache TRUE: Do not use cache for this request. (Default: FALSE) * @return YellowTree\GeoipDetect\DataSources\City GeoInformation. * * @since 2.0.0 * @since 2.4.0 New parameter $skipCache * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property */ function geoip_detect2_get_info_from_current_ip($locales = null, $options = array()) { return geoip_detect2_get_info_from_ip(geoip_detect2_get_client_ip(), $locales, $options); }
function testTrustedProxies() { add_filter('pre_option_geoip-detect-trusted_proxy_ips', 'test_set_trusted_proxies', 101); $_SERVER['HTTP_X_FORWARDED_FOR'] = GEOIP_DETECT_TEST_IP . ', 1.1.1.1'; $this->assertSame(GEOIP_DETECT_TEST_IP, geoip_detect2_get_client_ip()); $_SERVER['HTTP_X_FORWARDED_FOR'] = GEOIP_DETECT_TEST_IP . ', 1.1.1.1, 2.2.2.2'; $this->assertSame(GEOIP_DETECT_TEST_IP, geoip_detect2_get_client_ip()); $_SERVER['HTTP_X_FORWARDED_FOR'] = '2.2.2.3, ' . GEOIP_DETECT_TEST_IP . ', 1.1.1.1'; $this->assertSame(GEOIP_DETECT_TEST_IP, geoip_detect2_get_client_ip()); $_SERVER['HTTP_X_FORWARDED_FOR'] = '2.2.2.2, ' . GEOIP_DETECT_TEST_IP . ', 1.1.1.1'; $this->assertSame(GEOIP_DETECT_TEST_IP, geoip_detect2_get_client_ip()); $_SERVER['HTTP_X_FORWARDED_FOR'] = '3.4.5.6, ' . GEOIP_DETECT_TEST_IP . ', 2.2.2.2, fe80:0:0:0:202:b3ff:fe1e:8329'; $this->assertSame(GEOIP_DETECT_TEST_IP, geoip_detect2_get_client_ip()); }
?> </p> <p> <input type="checkbox" name="options[has_reverse_proxy]" value="1" <?php if (!empty($wp_options['has_reverse_proxy'])) { echo 'checked="checked"'; } ?> > The server is behind a reverse proxy<em> <span class="detail-box"> <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { ?> <?php printf(__('(With Proxy: %s - Without Proxy: %s - Client IP with current configuration: %s)', 'geoip-detect'), $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR'], geoip_detect2_get_client_ip()); ?> <br /> <?php } else { ?> <?php echo "(This doesn't seem to be the case.)"; ?> <?php } ?> </em> </span> </p> <p>
</p> <h2>Test Lookup</h2> <form method="post" action="#"> <?php wp_nonce_field('geoip_detect_lookup'); ?> <input type="hidden" name="action" value="lookup" /> <?php _e('IP', 'geoip-detect'); ?> : <input type="text" placeholder="<?php _e('Enter an IP (v4 or v6)', 'geoip-detect'); ?> " name="ip" value="<?php echo isset($_REQUEST['ip']) ? esc_attr($_REQUEST['ip']) : esc_attr(geoip_detect2_get_client_ip()); ?> " /><br /> <label><?php _e('Use these locales:', 'geoip-detect'); ?> <select name="locales"> <option value="" <?php if (empty($_POST['locales'])) { echo 'selected="selected"'; } ?> ><?php _e('Default (Current site language, English otherwise)', 'geoip-detect'); ?>
/** * Get client IP (even if it is behind a reverse proxy) * @deprecated since v2.0 */ function geoip_detect_get_client_ip() { return geoip_detect2_get_client_ip(); }
function geoip_detect2_shortcode_client_ip($attr) { $client_ip = geoip_detect2_get_client_ip(); geoip_detect_normalize_ip($client_ip); return $client_ip; }