我希望您能提供一种明确的方法来检测访问者是否来自中东。 如果是,我需要显示不同的标题图像(当前的图像中有一只猪,所以它被认为是不合适的)。
我可以编写if then else代码,但我只是在寻找一个简单的函数来进行检测。 这是一个我用过的根据IP获取国家的函数:
我可以编写if then else代码,但我只是在寻找一个简单的函数来进行检测。 这是一个我用过的根据IP获取国家的函数:
function get_country_by_ip($ip){
if(!$ip) return false; # Missing parameter
# Pull the XML
$url = 'http://api.hostip.info/?ip='.$ip;
$xml = simplexml_load_file($url);
# Parse the data and store into array
$citystate = explode(", ", $xml->children('gml', true)->featureMember->children()->Hostip->children('gml', true)->name);
$result['city'] = $citystate[0];
$result['state'] = $citystate[1];
$result['country'] = $xml->children('gml', true)->featureMember->children()->Hostip->countryName;
$result['country_abbr'] = $xml->children('gml', true)->featureMember->children()->Hostip->countryAbbrev;
return (object) $result;
}
有人可以帮忙吗?谢谢。