kungpung
07-15-2010, 02:48 AM
I have a page with a Geo IP redirect that's supposed to redirect users from London to URL#1 and the rest to URL#2. It's an external geo ip lookup service.
First comes the IP lookup:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js">
/*
GeoIP Deny Access by City and Redirect Javascript 1.0
http://wiki.category5.tv/MaxMind_GeoIP_API
API (c) MaxMind - www.maxmind.com - used with permission
"GeoIP Deny Access by City" script by Robbie Ferguson, www.Category5.TV
You are free to use and share this script, however this notice must remain intact.
*/
</script>
And then, and here's the problem I think, is the redirects inside an if/else:
<script type="text/javascript">
var city=new Array("London, H9")
var redirect="http://www.URL1.com"
var redirect2="http://www.URL2.com"
/* do not edit past this line */
Array.prototype.inArray = function(q) {
for(i in this) { if(this[i].toUpperCase() === q) return true; }
}
var myCity=geoip_city().toUpperCase()
var myRegion=geoip_region().toUpperCase()
if(city.inArray(myCity+", "+myRegion))
{
window.location = redirect;
}
else
{
window.location = redirect2;
}
The redirect works if you are indeed from London. So if the if-statement is true, "window.location = redirect" works, but if the statement is not true, "window.location = redirect2" doesn't seem to be called.
Help would be extremely appreciated :)
First comes the IP lookup:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js">
/*
GeoIP Deny Access by City and Redirect Javascript 1.0
http://wiki.category5.tv/MaxMind_GeoIP_API
API (c) MaxMind - www.maxmind.com - used with permission
"GeoIP Deny Access by City" script by Robbie Ferguson, www.Category5.TV
You are free to use and share this script, however this notice must remain intact.
*/
</script>
And then, and here's the problem I think, is the redirects inside an if/else:
<script type="text/javascript">
var city=new Array("London, H9")
var redirect="http://www.URL1.com"
var redirect2="http://www.URL2.com"
/* do not edit past this line */
Array.prototype.inArray = function(q) {
for(i in this) { if(this[i].toUpperCase() === q) return true; }
}
var myCity=geoip_city().toUpperCase()
var myRegion=geoip_region().toUpperCase()
if(city.inArray(myCity+", "+myRegion))
{
window.location = redirect;
}
else
{
window.location = redirect2;
}
The redirect works if you are indeed from London. So if the if-statement is true, "window.location = redirect" works, but if the statement is not true, "window.location = redirect2" doesn't seem to be called.
Help would be extremely appreciated :)