I wanna display user\'s/visitor\'s country flag on my site.
I am using different technologies like php,jsp and simple html. So I want a code which by placing on my site,
My service, ipdata.co provides an IP Geolocation API on https://api.ipdata.co and serves flags on for example https://ipdata.co/flags/cu.png.
All you have to do is know your visitors' country's iso code and you can fill it in
ipdata.co/flags/country-code.png
You can of course get the user's country code by calling https://api.ipdata.co/user-ip.
Sample embed;
<img src="https://ipdata.co/flags/us.png" alt="Smiley face">
Gives
Edit
We now also provide you with the country emoji flag and country emoji unicode.
Source :
http://www.shorter.in/#flag
<a href="http://www.shorter.in/#flag" target="_blank"><img src="http://shorter.in/flag.php"></a>
Example for the code given above.
a busy cat http://shorter.in/flag.php
I guess this is what you are looking for.
You can use the GeoIP extension and then map the country in question to a given icon.
$countryName = geoip_country_name_by_name($_SERVER['REMOTE_ADDR']);
echo $countryName;
Note that getting the country via IP is not exact.
Yeah there is something already available and you don't have to reinvent the wheel.
Check this thing out.
http://api.hostip.info/flag.php?ip=12.215.42.19
Grab your user's IP using PHP and pass it to the API.
<?php
$ip=$_SERVER['REMOTE_ADDR'];
?>
<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo "<img src='http://api.hostip.info/flag.php?ip=$ip' />";
?>
Get the IP of visitor.
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
Use ip2location to find the country of the user.
http://dev.maxmind.com/geoip/legacy/geolite/
Compare the resulting country to a list of images and display the matching image. I suggest using a database to store the country name and the path to the associated image.