Forum Moderators: coopster
<?php
session_start();
if(!isset($lang)) {
$lang = getenv('HTTP_ACCEPT_LANGUAGE');
$lang_default = "fr";
}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");
}
?>
I am thinking your setup has register_globals on so you may want to use something different than lang as your varname
maybe 'linklang' and setup a test like so
<?php
session_start();
if (isset($_GET['linklang'])) {
$_SESSION['lang'] = $_GET['linklang'];
}
if(!isset($lang)) {
$lang = getenv('HTTP_ACCEPT_LANGUAGE');
$lang_default = "fr";
}
$langs = array('fr','en');
session_start();
if(isset($_GET['l']) && [url=http://www.php.net/in-array]in_array[/url]($_GET['l'], $langs)) {
$_SESSION['lang'] = $_GET['l'];
} else {
$_SESSION['lang'] = 'en';
}
[url=http://www.php.net/header]header[/url]("Location: http://www.example.com/lang/index.".$_SESSION['lang'].".php");
exit;
Now the links on your page would be something along these lines:
<a href="index.php?l=fr">French</a>
<a href="index.php?l=en">English</a>
lang/en/index.php
lang/fr/index.php
instead of
lang/index.en.php
lang/index.fr.php
The second method can get sloppy.
I'm not sure I understand your response...
I think I understand the response, because I have a comparable language setup on one of my sites. index.XX.php files are automatically selected by the language content negotiation phase when the web browser connects to the server. With this automatic negotiation the larger part of the visitors (80% or more) will already get the language version they need without the need to do an additional language selection. The 20% unsatisfied visitors can select their own language by clicking on a link to another language version.
Content negotiation works with filenames like index.en.php, index.de.php etc, but not with sites where the languages are split in directories like /en/... /de/... etc.