Topic: please help with lang file...
Hi all;
I'm new to php , at the moment i'm trying to make a website which visitor can switch the language on the fly ( no need database) and in the same site(page)..like punbb; the user can choose the language by using lang files.
Here is my script for index.php (main page)
<?php
session_start();
if(!isset($lang)) {
$lang = getenv('HTTP_ACCEPT_LANGUAGE');
$lang_default = "en";
}
if (is_file("lang/index.$lang.php"))
{
$_SESSION["lang"] = $lang;
include("lang/index.$lang.php");
} else {
$_SESSION["lang"] = $lang_default;
include("lang/index.$lang_default.php");
}
?>
<body>
<form action="<?php echo $PHP_SELF;?>" method="get">
<select name="lang" size="1" onchange="this.form.submit()">
<option value="en">English</option>
<option value="cn">France</option>
</select>
</form>
<p><?PHP echo main;?></p>
</body>
and here is my index.en.php
<?PHP
define("main", "How it works?");
?>
but the problem is i cant switch it; it always is at the default lang; i cant switch to others. But if i put the form and the script away from the main page. Let the user choose language frist then can access to the main page then it can work.
Can you guys please help to show how i can get it works inside the web page. So they can always switch the language at the page they are at.
Please help
Thank you very much