Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get user's country flag on my site

Tags:

html

php

jsp

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.

like image 637
Johny Pie Avatar asked Nov 04 '13 12:11

Johny Pie


People also ask

How do I add a country flag in WordPress?

Via the WordPress admin go to Plugins => Add New. Enter 'SVG Flags' (without quotes) in the text box and click the 'Search Plugins' button. In the list of relevant Plugins click the 'Install' link for SVG Flags on the right hand side of the page. Click the 'Install Now' button on the popup page.

How do countries get flags?

National flags. The colours and designs of national flags usually are not arbitrarily selected but rather stem from the history, culture, or religion of the particular country. Many flags can be traced to a common origin, and such “flag families” are often linked both by common traditions and by geography.


3 Answers

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.

like image 105
rickj Avatar answered Oct 11 '22 22:10

rickj


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="US Flag">

Gives

US Flag

Edit

We now also provide you with the country emoji flag and country emoji unicode.

like image 31
Jonathan Avatar answered Oct 11 '22 21:10

Jonathan


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'];
?>

Putting it all together

<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo "<img src='http://api.hostip.info/flag.php?ip=$ip' />";
?>
like image 34
Shankar Narayana Damodaran Avatar answered Oct 11 '22 20:10

Shankar Narayana Damodaran