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,
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.