开发者

Display flag according to Browser region

开发者 https://www.devze.com 2023-02-15 02:55 出处:网络
On the top of my website I want a flag to show which represents the users region, i.e. browser region.

On the top of my website I want a flag to show which represents the users region, i.e. browser region.

does any one have any idea on how to achieve this?

Thanks for any ideas/suggestions

edit: after some confusion开发者_StackOverflow社区, I am talking about location not language.


Use the MaxMind GeoLite Country API to determine the user's country. They also offer a PHP module which should make it easier for you.

Once you have the user's country, you'll need to map it to a flag. Here's a free flag icon set: http://www.famfamfam.com/lab/icons/flags/

Integration details:

$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

echo '<img src="' . $country . '.png">';

You'll need to read up on the PHP module but that's the quick code on how to output an image tag with the country code.


infodb provide a free geolocation service - or the data required to roll your own.

0

精彩评论

暂无评论...
验证码 换一张
取 消