我正在尋找一種明確的方法來檢測訪客是否來自中東。如果是這樣,我需要顯示一個不同的標題圖片(目前的圖片中有一個豬,所以它是皺眉)。如何通過PHP檢測中東訪問者?
我可以編碼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;
}
任何人都可以幫忙嗎?謝謝。
如果你從上面的國家有什麼問題? - 這也永遠不能保證你對國家的權利 – 2011-10-05 20:44:51
亞太地區的穆斯林人數是中東地區的3倍。非洲。請參閱[維基百科](http://en.wikipedia.org/wiki/List_of_countries_by_Muslim_population) –