0

当用户来自特定国家/地区时,如何重定向来自特定域的传入流量?

例如:

从 example.com 到我的网站的墨西哥流量和从 newexample.com 到我的网站的中国流量和...

谢谢你

[ **编辑更多信息** ]

我正在寻找一个代码来重定向来自以下示例域的传入流量,前提是该流量也来自我列表中域前面的指定国家/地区。请在您提供的代码中包含我的示例域以及目标重定向 url:

site1.com 巴西 >> 重定向
site2.com 墨西哥 >> 重定向
site3.com 辣椒 >> 重定向
site4.com 阿根廷 >> 重定向
site5.com 哥伦比亚 >> 重定向
site6.com 印度 >> 重定向
site7.com 印度 >> 重定向

谢谢

4

1 回答 1

0
<?php

        $ip = $_SERVER['REMOTE_ADDR'];
        $url = "http://api.ipinfodb.com/v3/ip-city/?key=<API KEY>&ip=$ip&format=json";


        $ch = curl_init(); // start CURL
        curl_setopt($ch, CURLOPT_URL, $url); // set your URL
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // get the response as a variable
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);      
        $response = curl_exec($ch); // connect and get your response 
        curl_close($ch);    
        $json_response = json_decode($response, true);

        echo "<pre>";
        print_r($json_response);
        echo "</pre>";
?>

上面的代码将根据用户的 IP 为您提供用户的位置,现在只需根据用户的位置通过一些 if else 重定向用户

请注意,您必须在此处注册以获取 api 密钥才能使用它

于 2013-09-24T17:12:26.543 回答