Answer the question
In order to leave comments, you need to log in
How to make an automatic redirect to the selected language?
Hello everyone!)
Recently I decided to make the site two languages - Russian and English. I have different pages for each language. My Russian language is just on the example.com domain , and English on example.com/en/ . And I want to make sure that when the user enters and selects English, when entering example.com, he (the user) is automatically redirected to example.com/en/
How to do this? Thanks in advance! :)
Answer the question
In order to leave comments, you need to log in
<a href="/lang.php?lang=en">En</a>
lang.php:
$lang = $_GET['lang'];
$_SESSION['lang'] = $lang;
header('Location: /'.$lang);
index.php:
if(!isset($_SESSION['lang']) {
$_SESSION['lang'] = 'ru';
}
if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'en') {
header('Location: /en');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question