我想在cf 7下拉列表中获取当前国家(通过IP查找)。
下面我通过IP查找国家:
function wpcf7_custom_date_shortcode_handler($mycountry) {
$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;
return $mycountry;
}
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;
}
下面的联系表7表单标签:
国家[选择*国家清单id:国家“请选择国家”“美国|美国”“阿富汗| AFG”“阿尔巴尼亚| ALB”“阿尔及利亚| DZA”“美属萨摩亚| ASM” ... .....]
(注意:...表示列出所有定义的国家)您可以使用此插件在表单电子邮件中获得用户跟踪详细信息。 Lead info with country for Contact Form 7