当用户来自特定国家时,如何从特定域重定向传入流量?
例如:
墨西哥的流量从example.com到我的站点,中国的流量从newexample.com到我的站点.
谢谢
**EDIT和更多的INFORMATION**
我正在寻找一个代码,它重定向来自以下示例域的传入通信量,条件是该通信量也来自我列表中域前面的指定国家。请在您提供的代码中包括我的示例域和目标重定向url:
站点1.com巴西>>重定向
网站2.com墨西哥>>重定向
site3.com辣椒>>重定向
网站4.com阿根廷>>重定向
站点5.com哥伦比亚大学>>重定向
站点6.com印度>>重定向
站点7.com印度>>重定向
谢谢
发布于 2013-09-24 17:12:26
<?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给出用户的位置,现在只需根据他的位置通过一些(如果不是其他)重定向用户。
请注意,您必须注册这里才能获得api密钥,才能使用此
https://stackoverflow.com/questions/18987853
复制相似问题