以下GeoIP2 javascript仅重定向到"else"URL,而不考虑国家/地区。它并没有重定向到该国家的正确URL,而是将所有流量发送到"其他"URL。。。我做错了什么?我该怎么解决?
<script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"></script>
<script language="JavaScript">
geoip2.country(
function (response) {
if (response.country.iso_code == "AU") {
window.location = "http://track.cpapower.net/tiny/nEZJp?transid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&_ocid=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&offerid=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "CO") {
window.location = "http://funloadia.com/whatsapp/coweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "DE") {
window.location = "http://funloadia.com/whatsapp/demob.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "EC") {
window.location = "http://funloadia.com/whatsapp/ecweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "FR") {
window.location = "http://funloadia.com/whatsapp/frweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "ES") {
window.location = "http://funloadia.com/whatsapp/esweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "KE") {
window.location = "http://funloadia.com/whatsapp/keweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "MX") {
window.location = "http://funloadia.com/whatsapp/mxweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "MY") {
window.location = "http://funloadia.com/whatsapp/myweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "NL") {
window.location = "http://funloadia.com/whatsapp/nlweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "PT") {
window.location = "http://funloadia.com/whatsapp/myweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "RO") {
window.location = "http://funloadia.com/whatsapp/myweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "SG") {
window.location = "http://funloadia.com/whatsapp/myweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
if (response.country.iso_code == "ZA") {
window.location = "http://funloadia.com/whatsapp/myweb.php?sid=<?php echo str_replace("-", " ", $_GET["sid"]); ?>&sid2=<?php echo str_replace("-", " ", $_GET["sid2"]); ?>&sid3=<?php echo str_replace("-", " ", $_GET["sid3"]); ?>"
}
else {
window.location = "http://funloadia.com/whatsapp/"
}
}
);
</script>
我认为你的代码的问题是你有if
条件,最后有else
,它在任何情况下都会执行,所以试着使用if..elseif..else
,如:
if (response.country.iso_code == "AU") {
window.location = ". . . ";
}
else if (response.country.iso_code == "CO") {
window.location = ". . .";
}
. . .
else {
window.location = "http://funloadia.co..";
}
我相信我已经解决了这个问题。我需要在其他国家的"if"前面加上"else"!就像在GeoIP1 中一样