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, visitors can see and it should run in all platform.
In short I want country detection API. If anybody can help me, I'll be very thankful.
Yeah there is something already available and you don't have to reinvent the wheel.
Check this thing out.
Grab your user's IP using PHP and pass it to the API.
Putting it all together
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
You can of course get the user's country code by calling https://api.ipdata.co/user-ip.
Sample embed;
Gives
Edit
We now also provide you with the country emoji flag and country emoji unicode.
You can use the GeoIP extension and then map the country in question to a given icon.
Note that getting the country via IP is not exact.
Source :
http://www.shorter.in/#flag
Example for the code given above.
a busy cat http://shorter.in/flag.php
I guess this is what you are looking for.
Get the IP of visitor.
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.