开发者

Discriminating between UK based and US based visitors

开发者 https://www.devze.com 2023-04-06 16:29 出处:网络
Apparently, $_SERVER[\"HTTP_ACCEPT_LANGUAGE\"] can be equal to \'en-us\', \'en\', \'us\' or \'en-gb\'. Question : is this variable a reliable way of knowin开发者_如何学编程g whether a visitor is US or

Apparently, $_SERVER["HTTP_ACCEPT_LANGUAGE"] can be equal to 'en-us', 'en', 'us' or 'en-gb'. Question : is this variable a reliable way of knowin开发者_如何学编程g whether a visitor is US or UK based ?

(I don't need 100% reliability but at least say 70%)


You could try using a webservice for IP-to-Country type geolocation. Try this one: http://www.hostip.info/use.html

Example Usage: http://api.hostip.info/?ip=12.215.42.19


By IP: http://www.geoplugin.com/

By Webbrowser if you have a database with countries and latitude/longitude info:

if (navigator.geolocation)
    navigator.geolocation.getCurrentPosition(getGPSLocation);

function getGPSLocation(location) {
    locationGPS=location;
    alert('location \n'+
            'latitude:'+location.coords.latitude+'\n'+
            'longitude:'+location.coords.longitude+'\n'+
            'acurracy:'+location.coords.accuracy);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号