I need detect user's country and show website's language by him / her country . (Turkish for Turkish people, English for all others)
How can i do this fastest way ? Performance is important for me .
I'm looking IPInfoDB' API , are there any better alternative ?
(I'm using PHP)
Well for people who might visit in 2017 this is a solution this extremely simple to use
<button class="btn dropdown-toggle" style="cursor:pointer;z-index:1000!important;margin-top:-67px;background:none!important;font-size:1.4em;" onclick="window.location.href='language'">
(a) <?php
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'];
}
$url = "http://api.wipmania.com/".$ip;
(h) $country = file_get_contents($url); //ISO code for Nigeria it is NG check your country ISO code
?>
<?php if ($country == ""){
echo "Country not found";
} else { ?>
<script>
var map = "<?php echo $country ?>";
$.ajax({
type : 'POST',
url : 'http://www.mowemy.com/countryflag.php',
data : {map: map},
success : function(r) {
//console.log("success: " + r);
$('#mumil').html(r);
} })
</script>
<?php } ?>
<div id ="mumil" style="font-size:13px!important;margin-top:5px;"></div>
</button>
let me beak it down letter A - H is the script to detect your ISO number for the country for my country Nigeria it is NG you can google search your countries ISO number, with this script it is auto detected. Then i created a page with some info you fire AJAX to that page which it sends back the country flag color and name simple and easy PLEASE CALL JQUERY BEFORE AJAX TO RUN THE AJAX UNLESS IT WONT WORK GOODLUCK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With