Reputation: 13
I would like to be able to detect if visitors to a webpage are situated in the USA and if they are I would like to redirect them to a different page.
I've been googling for some script that could do this but haven't found anything. Can someone point me in the right direction?
I'd ideally like to be able to achieve it with Javascript and/or HTML5 but if that's not possible please do let me know about alternatives.
Upvotes: 1
Views: 3117
Reputation: 1
There are some scripts to solve your problem (in PHP): http://www.phptutorial.info/iptocountry/the_script.html
Summary:
aletrnative solution is to use webservice http://freegeoip.net/, but there is daily limit for requests.
Upvotes: 0
Reputation: 7577
A tutorial from here: GeoDirection
<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet"></script>
<script language="Javascript">
if(typeof(sGeobytesLocationCode)=="undefined"
||typeof(sGeobytesCode)=="undefined"
||typeof(sGeobytesInternet)=="undefined")
{
// Something has gone wrong with the variables, so set them to some default value,
// maybe set a error flag to check for later on.
var sGeobytesLocationCode="unknown";
var sGeobytesCode="unknown";
var sGeobytesInternet="unknown";
}
if(sGeobytesLocationCode=="GRATATHE")
{
// Visitors from Athens would go here
window.open("enter Athens URL here");
}else if(sGeobytesCode=="AT")
{
// Visitors from Attiki would go here
window.open("enter Attiki URL here");
}else if(sGeobytesInternet=="GR")
{
// Visitors from Greece would go here
window.open("enter Greece URL here");
}
</script>
Upvotes: 2