Answer the question
In order to leave comments, you need to log in
How to implement multilingualism in php using cookies?
setcookie('lang', $_POST['lang']);
if(session_start()) {
$_SESSION['lang'] = $_COOKIE['lang'];
} else {
$_SESSION['lang'] = $_POST['lang'];
}
$lang = $_SESSION['lang'];
$defaultlang = 'rus';
if (!isset($lang))
{
$lang = (!file_exists("./lang/{$lang}.php")) ? $defaultlang : $lang;
}
echo "lang=".$lang;
require "./lang/{$lang}.php";
<form action="?set=lang" method="post">
<select name="lang">
<option value="rus">ru</option>
<option value="eng">en</option>
</select>
<input type="submit" value="ok" />
</form>
Answer the question
In order to leave comments, you need to log in
As an option, parse the "Accept-Language" header and immediately issue the "preferred language" along with the cookie. Which, say, we change if necessary (when choosing another language through the select, we update the page, load the desired language and set the cookie)
I use the following scheme for myself:
site.ru/some_page
site.ru/en/some_page
You can also ru.site.ru / en.site.ru, etc. I
use this scheme because search engines look for special links on the page, which, as it were, say that this page exists in N languages. Thus, they understand that this is the same content.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question