php - Fetching country from IP using wordpress plugin GeoIP detection? -
i've installed plugin: https://tah.wordpress.org/plugins/geoip-detect/
the plugin seems work fine when test "lookup" within plugin, returns geo-information. when try implement code within 1 of wordpress pages doesn't work.
$ip = $_server['remote_addr']; $userinfo = geoip_detect2_get_info_from_current_ip($ip); echo $userinfo->country->name;
i'm calling function native woocommerce page single-products shown. fucntion returns nothing. have include more call function geoip_detect2_get_info_from_current_ip()?
i tried:
<?php echo do_shortcode("[geoip_detect2 property='country']"); ?>
it doesn't return either. i'm doing editing within godaddy's code editing tool, might missing errors.
i have try implement geo ip in wordpress site http://iradiofind.com/stations/. using http://www.geoplugin.net country info. got ip address using function
function get_client_ip() { $ipaddress = ''; if (getenv('http_client_ip')) $ipaddress = getenv('http_client_ip'); else if(getenv('http_x_forwarded_for')) $ipaddress = getenv('http_x_forwarded_for'); else if(getenv('http_x_forwarded')) $ipaddress = getenv('http_x_forwarded'); else if(getenv('http_forwarded_for')) $ipaddress = getenv('http_forwarded_for'); else if(getenv('http_forwarded')) $ipaddress = getenv('http_forwarded'); else if(getenv('remote_addr')) $ipaddress = getenv('remote_addr'); else $ipaddress = 'unknown'; return $ipaddress; } function ip_details($url) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer,1); $data = curl_exec($ch); curl_close($ch); return $data; }
and in page template.
<?php $myipd = get_client_ip(); $url = 'http://www.geoplugin.net/json.gp?ip='.$myipd; $details = ip_details($url); $v = json_decode($details); $mycountry = $v->geoplugin_countryname; ?>
Comments
Post a Comment