1
I have a code on PHP
created by @Maia, it informs the browser language and returns with a redirecting.
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 thing would be for him to redirect to meusite.com/pt-BR
because my browser has the language pt-BR
.
Did creating a split
would solve?
Member @Maia did so:
$lang = split(",", $_SERVER['HTTP_ACCEPT_LANGUAGE'])[0];
In case the URL would only go to the first comma, leaving so only: meusite.com/pt-BR
.
Only the code seems to be wrong, it doesn’t work.
I would like to do this with the URL, leaving up /pt-BR
, or even leave it:
meusite.com/pt
The member suggested that I change the index from [0] to 1 leaving so:
$lang = split(",", $_SERVER['HTTP_ACCEPT_LANGUAGE'])[1];
It just doesn’t work, so I’d like some example of how to get it redirected to /en or how to redirect to /pt
Is the classic Problemaxy. In my humble opinion, the original question it was much better, but it seems to me that you gave Accept in the first answer, that although good it might not have solved entirely your problem.
– Bacco
@Bacco How can I fix this? Help me again man! rs
– Alexandre Lopes
It solves, now my doubt is just how to change the URL. #Simply
– Alexandre Lopes
I can’t help you at the moment, because I’m working on other things, but let’s hope someone gives you more options on that issue, because there are several ways to deal with it. Even servers like Apache already have this feature internally, you may notice that the default installation (the welcome page of apache) meets the language of the sew browser automatically, even without PHP: https://httpd.apache.org/docs/2.2/content-negotiation.html
– Bacco
Whenever I ask for help from you, you say you are busy... Typical. rsrsrs More has no problem! ;)
– Alexandre Lopes
Follow a solution without much optimization, just for you to stop mimimi :P
– Bacco