I work with php5 and apache2 on my development machine. The production server is apparently similar.
I have a script set_language.php that creates a session variable according to the language chosen:
<?php
session_start();
$back = $_SERVER['HTTP_REFERER'];
if (isset($_GET['lang'])) {
if ($_GET['lang'] == 'fr')
$_SESSION['lang'] = 'fr';
else if ($_GET['lang'] == 'en')
$_SESSION['lang'] = 'en';
}
header( "Location: $back" ) ;
exit();
?>
Then I include the code below on all pages:
session_start();
if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'en') {
require('lang_en.php');
}
else if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'fr') {
require('lang_fr.php');
}
Than I can get language-dependent variables with:
echo $lang[sometexttotranslate];
On the development server it works as expected. I click on the link to set the language and my session variables contain lang=en or fr
On the production server:
$_SESSION['lang'] = dn or dr (should be en or fr)
echo $lang[sometexttotranslate] = d (should be a translated text)
Any idea where the "d"'s come from?
This is not a redirection/header/session_start() problem.
print_r($_SESSION) on first load:
Array ( [lang] => fr )
print_r($_SESSION) after a click on the english link (set_lang.php above):
Array ( [lang] => dn )
print_r($_SESSION) after a click on the french link (set_lang.php above):
Array ( [lang] => dr )
print_r($_SESSION) after login:
Array ( [lang] => dr [valid] => 1 [pseudo] => GYC [uid] => 3 )
See Question&Answers more detail:os