编辑:不是重复开始。最初是如何改进或使用不同的代码重定向基于访问者的国家。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