EDIT: Wasn't a duplicate to began with. Originally was how to improve or use different code to redirect based on the visitor's COUNTRY.
Here is the code I'm currently using:
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');
}
on a couple of static (html + javascript) viral sites that bring in around 100,000 visitors a day, sometimes more and sometimes less.
Are there any better (and free) solutions to redirect based on country? I recently switched from a dedicated server to a VPS and the current code seems to use a lot of CPU usage (or so I'm told by my host). I'll probably just go back to the dedicated server but I would still like to know if there is a better way, one that doesn't stress the server as much.
Also, since I'm redirecting based on language:
// 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');
}
and extremely tired right now, what's the better way? this or no:
//english
if ($country == 'US') || ($country == 'CA') {
header('Location: http://us.mysite.com');
}
So anyone visiting from US or Canada would be redirected to google.com
Thanks in advance