GeoIP2 Javascript仅限重定向到其他但不是特定国家/地区

时间:2015-03-06 07:54:28

标签: javascript maxmind

以下GeoIP2 javascript仅重定向到" else" 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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我认为您的代码存在的问题是您最终有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..";
}

答案 1 :(得分:0)

我相信我解决了这个问题。我需要在“if”前面为其他国家添加“else”!就像在GeoIP1中一样