php maxmind geoip exception ip


php maxmind geoip exception ip

我使用Maxmid geoap脚本(php)根据用户的位置重定向用户(www.mysite.com-针对本问题)。英国游客将前往英国网站,而其他人将留在当前网站。然而,我也想为我的ip设置一个例外,这样我就可以查看这两个网站(前提是我的ip与文件中给出的匹配——我在英国)。下面是我的编码,它不适用于"异常ip"。

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/geoip/geoip.inc");
$gi = geoip_open($_SERVER['DOCUMENT_ROOT']."/geoip/GeoIP.dat", GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
$useragent_country = array('gb');
$exception_ip = "80.47.200.21";
if (in_array(strtolower($country), $useragent_country)){
    header('location: http://www.mysite.co.uk');
    exit();
} 
if ($_SERVER['REMOTE_ADDR'] = $exception_ip){
    header('location: http://www.mysite.com');
}
?>

此外,为了将"异常ip"保留在当前站点上,我的编码是否正确?

我最终做到了。将异常ip放入数组意味着我可以添加任意数量的异常ip。此外,$uri意味着它将在重定向时转到相同的路径:

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/geoip/geoip.inc");
$gi = geoip_open($_SERVER['DOCUMENT_ROOT']."/geoip/GeoIP.dat", GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
$useragent_country = array('gb');
$uri = $_SERVER['REQUEST_URI'];
$exception_ip = array("1.2.3.4.5");//ADD IPs here in array form
if(in_array($_SERVER['REMOTE_ADDR'], $exception_ip)){
//do nothing
}
else{
if (in_array(strtolower($country), $useragent_country)){
    header('location: http://www.mysite.co.uk$uri');//redirect to same path
    exit();
} 
}
?>