Hello,
I am very new to .php and I am experiencing some issues with my script. I will do the best to explain what I am trying to accomplish.
My website has three languages. I have a English, Spanish and Portuguese version. Currently I have a language selector at the top of each page. So the user can choose which language they would like to view. Works great, BUT I would like to have their language come up without them having to choose.
I found in the abyss of the internet some tutorials on building this script.
The first one was:
function redirect()
{
$lang=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2)=='en')
{
header("Location: http://www.mydomain.com/en/");
} else {
header("Location: http://www.mydomain.com/sp");
}
}
redirect();
Which worked perfect, but I have three languages not 2. So I then found:
function redirect()
{
$lang=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
switch($lang) {
case "en":
header("Location: http://www.mydomain.com/en/");
break;
case "pt":
header("Location: http://www.mydomain.com/po/");
break;
case "es":
header("Location: http://www.mydomain.com/sp/");
break;
default "en":
header("Location: http://www.mydomain.com/en/");
}
redirect();
And this script is not working for me. Nothing comes up. Any Ideas?
Thank you for your time.🙂😕