I am having a code in PHP
, it informs the browser language and returns with a redirect .
Code
<?php
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
header("Location: http://meusite.com/$lang" ) ;
?>
It redirects to:
meusite.com/pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
The right one would be to redirect to meusite.com/pt-BR
because my browser has the language pt-BR
.
Will creating a split
solve?
The member Maia did so:
$lang = split(",", $_SERVER['HTTP_ACCEPT_LANGUAGE'])[0];
In case the URL would only go to the first comma, leaving only: meusite.com/pt-BR
.
But the code seems to be wrong, does not work.
I would like to do this with the URL, leaving up /pt-BR
, or even leaving it:
meusite.com/pt
The member suggested that I change the index from [0] to 1 thus leaving:
$lang = split(",", $_SERVER['HTTP_ACCEPT_LANGUAGE'])[1];
It just does not work, so I would like some example of how to redirect it to / en-US or how to redirect to / en