I'm looking for a clear cut way to detect if a visitor is from the Middle East. If they are, I need to display a different header image (the current one has a hog in it, so it is frowned upon).
I can code the if then else for that, but I'm just looking for a simple function to detect. Here's a function I used to get the country by 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;
}
Can anyone help? Thanks.