如何从特定国家/地区重定向用户
How do I redirect users from a specific country?
我希望能够检测网页的访问者是否位于美国,如果他们位于美国,我想将他们重定向到不同的页面。
我一直在谷歌上搜索一些可以做到这一点的脚本,但没有找到任何东西。有人可以指出我正确的方向吗?
理想情况下,我希望能够使用Javascript和/或HTML5实现它,但如果这是不可能的,请告诉我替代方案。
这里的
教程:地理方向
<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet"></script>
<script language="Javascript">
if(typeof(sGeobytesLocationCode)=="undefined"
||typeof(sGeobytesCode)=="undefined"
||typeof(sGeobytesInternet)=="undefined")
{
// Something has gone wrong with the variables, so set them to some default value,
// maybe set a error flag to check for later on.
var sGeobytesLocationCode="unknown";
var sGeobytesCode="unknown";
var sGeobytesInternet="unknown";
}
if(sGeobytesLocationCode=="GRATATHE")
{
// Visitors from Athens would go here
window.open("enter Athens URL here");
}else if(sGeobytesCode=="AT")
{
// Visitors from Attiki would go here
window.open("enter Attiki URL here");
}else if(sGeobytesInternet=="GR")
{
// Visitors from Greece would go here
window.open("enter Greece URL here");
}
</script>
有一些脚本可以解决您的问题(在PHP中): http://www.phptutorial.info/iptocountry/the_script.html
总结:
- $_SERVER['REMOTE_ADDR'] = 用于检测访问者 IP 地址的变量
- 在上面的页面上下载IP地址范围列表(您可以选择特定的国家列表或下载所有国家) - 每个国家都有IP地址范围
AletrNative 解决方案是使用 Web 服务 http://freegeoip.net/,但请求有每日限制。
相关文章:
- 通过javascript重定向html传递php变量
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 使用angular重定向到html页面
- 如何在chrome扩展中重定向到html页面
- 无法从jquery Mobile导航栏重定向到另一个页面
- ng视图外的链接重定向到ng视图内的页面
- 在phonegap应用程序内部重定向不起作用
- CORS-重定向到第二个GET正在接收的页面
- AJAX不会在文件上传后重定向到网页-POST方法
- 重定向时角度刷新浏览器
- 通过链接重定向不;我不在jstree中工作
- 根据select选项元素将表单重定向到不同的URL
- 通过JQuery重定向到另一个页面
- 重定向到“父窗口”
- 重定向iFrame中的父URL
- PHP-如何重定向到同一页面并更改DOM's
- 如何从特定国家/地区重定向用户
- 如何使用Maxmind Geoip2 Javascript根据国家/地区重定向流量
- 根据国家/地区重定向
- 根据用户所在国家/地区重定向网站