我不是专家,但我试图监控我的流量,我试图用代码创建页面,以检测用户Geo并将他们重定向到新页面。
但它看起来像是缺少了什么我不知道是什么
我试着使用这个Geo redirect user just once using php
但是我找不到我从哪里得到这个GeoIP.php
有人能告诉我我需要什么才能成功吗?
谢谢波阿兹
发布于 2014-03-30 19:58:47
你应该看看这个:http://www.php.net/manual/en/function.geoip-continent-code-by-name.php
简单地使用
$country = geoip_continent_code_by_name ( $_SERVER['REMOTE_ADDR'] );$country将返回2个字母的国家代码。以下是您应该能够使用的内容:
<?php
//Get the country code of the user, using REMOTE_ADDR is the most reliable way to do this
$country = geoip_continent_code_by_name ( $_SERVER['REMOTE_ADDR'] );
//Create a switch case to deal with the country codes
switch((string)$country) {
case 'AU':
$url = "http://www.site.au";
break;
case 'CA':
$url = "http://www.site.ca";
break;
//default case means, if you didn't provide a case (country code in your example), do this (otherwise known as a "catch all")
default:
$url = "http://defaultsite.com";
} //End switchcase
//This if statement says as long as $url is not empty (! means not), update header location (this is the php way of forwarding)
if ( !empty($url) ){
header('Location: '.$url);
} //End if statement
?>你会注意到我删除了尝试,捕捉块。这是用户偏好,但是,大多数人不喜欢它(使用开关大小写,这就是为什么您提供默认情况)。
这对你来说应该是100%的。
https://stackoverflow.com/questions/22748819
复制相似问题