A user selects a language ($lang_select) which has two possibilities for now: "en" and "nl". The choise is then stored in both a cookie and a session and they are used for further things in the site.
<?php
$cache_limiter = session_cache_limiter('private');
/* Expiration after 2 hours. */
$cache_expire = session_cache_expire(120);
if ((!in_array ($lang_select, $lang_array) || !isset ($lang_select)) AND (!isset ($_SESSION['lang_used']) && !isset ($_COOKIE['lang_used'])))
{
$lang_select = "en";
}
if (isset ($_SESSION['lang_used']))
{
if ($lang_select != $_SESSION['lang_used'])
{
/* Destroy old session and create a new one. */
session_unset();
session_destroy();
session_start();
session_register('lang_used');
$_SESSION['lang_used'] = $lang_select;
}
else
{
$lang_select = $_SESSION['lang_used'];
}
}
elseif (isset ($_COOKIE['lang_used']))
{
if ($lang_select != $_COOKIE['lang_used'])
{
setcookie ("lang_used", $lang_select, time() + 60*60*24*2);
session_start();
session_register('lang_used');
$_SESSION['lang_used'] = $lang_select;
}
else
{
$lang_select = $_COOKIE['lang_used'];
}
}
else
{
/* If nor a cookie nor a session has been set, create both. */
setcookie ("lang_used", $lang_select, time() + 60*60*24*2);
session_start();
session_register('lang_used');
$_SESSION['lang_used'] = $lang_select;
}
?>
If it's working correctly (which it isn't, because it doens't return anything) should return the variable $lang_select. BTW: It's included in every page, where it get his variable $lang_array, which is just an array like this: $lang_array = array ("en", "nl");