I am using following code to redirect users based on browser language:
if(!isset($_SESSION['lang'])){
if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT'])){
$_SESSION['lang'] = 'en';
header("location:index.php");
}else{
$_SESSION['lang'] = 'other';
header("location:http://cn.gearor.com");
}
}
I put the code in my WordPress theme, at the very beginning before DOCTYPE, and I got an error: unexpected '{' in header.php on line 1. I can't figure out what causes this.
Related: http://stackoverflow.com/questions/2352205/how-to-redirect-users-based-on-browser-language