一直有這個問題!反正我已經下載Maxminds GEOIP PHP模塊,並將其上傳到我的服務器,然後我把這段代碼到我的index.php頁面MaxMind GEO_IP重定向
<?php
require_once("geoip/geoip.inc");
$gi = geoip_open("geoip/GeoIP.dat",GEOIP_STANDARD);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
$my_countriesrow = array('AD','AE','AF'......and so on);
$my_countrieseuro = array('AN','AT','BA','BE','BG','BY'.......and so on);
/* $my_country = array('GB','UK'); */
if (!in_array(strtolower($country), $my_countriesrow)){
header('Location: https://www.website.com/row/index.php');
exit();
}
elseif (!in_array(strtolower($country), $my_countrieseuro)){
header('Location: https://www.website.com/euro/index.php');
exit();
}
else {
header('Location: https://www.website.com/index.php');
exit();
}
?>
我已經上傳網頁到我的服務器,並在谷歌瀏覽器我得到。 ... 此網頁有重定向循環
The web page at https://www.website.com/index.php has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
一樣在Firefox!任何人有任何想法,因爲我全力以赴......
在此先感謝!
-Phillip露水
UPDATE
OK決定下井的.htaccess ROUTE!我已經編輯我的htaccess文件是這樣的....
GeoIPEnable On
GeoIPDBFile /geoip/GeoIP.dat
# Europe
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AM$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AO$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AQ$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AR$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AS$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AU$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AW$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AX$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AZ$
RewriteRule ^(.*)$ https://www.Website.com/europe$1 [L]
# Rest Of World
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AD$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AE$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AF$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AG$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AI$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AL$
RewriteRule ^(.*)$ https://www.Website.com/row$1 [L]
但由於某種原因,我得到一個500內部錯誤,甚至把它仍然沒有工作對我來說每燎國後!真的不知道該怎麼做,因爲我一直在使用不同的PHP腳本工作了一個多星期,現在這個。希望任何人都可以提前幫助再次致謝,我要問的原因是有很多國家代碼需要手動輸入,所以不想把它們都放進去,以至於找不到它們!非常感謝!
-Phillip
感謝phihag,但已決定嘗試使用.htaccess,但即使那不工作吧!已更新我原來的問題!無論如何,感謝 – 2012-04-07 17:43:34