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';
hea开发者_如何学编程der("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: How to redirect users based on browser language
Can you please supply the code of your header.php? Your post does not tell us where to find line 1 of your code.
Wordpress encourages developers to use the function wp_redirect() for redirecting to other resources instead of sending header() like you would do in php.
For usage see: http://codex.wordpress.org/Function_Reference/wp_redirect
Related: http://wordpressapi.com/solved-header-function-issue-wordpress
精彩评论