I am assuming that $_GET['FirstTimer']
is not set. So your switch is always executed.
When geoip returns GR
your script will redirect to http://mywebsite.com/
again.
$_SERVER['REQUEST_URI']
returns /
and you are back in your switch again.
There is your loop.
EDIT
I've changed your script a little bit. Instead of logging if the user visits the first time, which makes no sense, just log when the user visited the last time. If this cookie is not set, start geoip and redirect the user. If it is set, update the time.
if(!isset($_COOKIE['last_visit'])) {
setcookie('last_visit',date("Y-m-d H:i:s"),strtotime('+1 year'),'/');
require_once('geoip.inc');
$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
if($_SERVER['REQUEST_URI'] == '/'){
switch((string)$country) {
case 'GR':
header('Location: http://mywebsite.com/');
break;
case 'RU':
header('Location: http://mywebsite.com/ru');
break;
default:
header('Location: http://mywebsite.com/en');
}
}
geoip_close($gi);
} else {
setcookie('last_visit',date("Y-m-d H:i:s"),strtotime('+1 year'),'/');
}
But you should definitely enhance this script because what happens, if you have a user that gets on your page with this: http://yourwebsite.com/great/article/link.html
.
Perhaps you do have a translation for this, but the user won't be redirected.