編輯:不是重複開始。最初是如何改進或使用不同的代碼重定向基於訪問者的國家。PHP GEO位置重定向 - 有沒有更好的解決方案?
這是我目前使用的代碼:一對夫婦的靜態(HTML + JavaScript的),在10萬左右的遊客帶來了一天的病毒網站,有時多有時少的
require_once('geo/geoip.inc');
$gi = geoip_open('geo/GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
if ($country == 'FR') {
header('Location: http://fr.mysite.com');
}
if ($country == 'US') {
header('Location: http://us.mysite.com');
}
。
有沒有更好的(和免費的)基於國家的重定向的解決方案?我最近從一個專用服務器切換到VPS,目前的代碼似乎使用了大量的CPU使用量(或者我的主機告訴我)。我可能會回到專用服務器上,但我仍然想知道是否有更好的方法,不會給服務器帶來太多壓力。
而且,因爲我基於重定向語言:
// french
if ($country == 'FR') {
header('Location: http://fr.mysite.com');
}
//french
if ($country == 'BE') {
header('Location: http://fr.mysite.com');
}
//french
if ($country == 'CA') {
header('Location: http://fr.mysite.com');
}
//english
if ($country == 'US') {
header('Location: http://us.mysite.com');
}
//english
if ($country == 'UK') {
header('Location: http://us.mysite.com');
}
和極度疲憊,現在,有什麼更好的辦法?這或無:
//english
if ($country == 'US') || ($country == 'CA') {
header('Location: http://us.mysite.com');
}
因此,任何從美國或加拿大的訪問將被重定向到google.com
在此先感謝
只需發送到google.com,它會重定向到您的國家/地區網站。或使用瀏覽器語言。 – 2016-06-09 23:50:17
我的錯,我只是以谷歌爲例。我會根據國家/地區將訪問者發送到我的網站的其他頁面或子域。獲取瀏覽器語言和重定向到合適頁面的最佳方式是什麼?當然我今晚晚些時候會谷歌它,但如果你有任何建議讓我知道。謝謝! – xetsr
downvote代碼你實際上並沒有使用 – 2016-06-09 23:55:28