A friend of mine gave me the solution. Activate the htaccess file in apache configuration. Edit your htaccess file and add:
RewriteEngine On
RewriteBase /
RewriteRule ^(en|fr|es|it|de)/(.*)$ $2?language=$1 [L,QSA]
Then in your php:
//Check if the select sends the Post lang
if (isset($_POST["lang"]))
{
$var =substr_replace($_SERVER['REQUEST_URI'], $_POST["lang"], 1,2) ;
header('Location:http://'.$_SERVER['HTTP_HOST'].$var);
}
//Redirect to EN laguage if no language is set in the URL, or Cookie
if (empty($_COOKIE["language"]) && empty($_GET["language"]))
{
header('Location:http://'.$_SERVER['SERVER_NAME'].':8000/'.'en/');
}
//Check if language cookie is here and if it's different from the url
if (isset($_COOKIE["language"]) && empty($_GET["language"]))
{
header('Location:http://'.$_SERVER['SERVER_NAME'].':8000/'.$_COOKIE["language"].'/');
}
elseif (isset($_GET["language"]))
{
$language = $_GET["language"];
setcookie ('language', $language, time() + 60*60*24*30, '/', 'localhost');
}
else
{
$language = 'en';
}
The language selector:
<form action="" method="post">
<select name="lang" onchange='this.form.submit()'>
<option value="en" {if $language == en}selected{/if}>En</option>
<option value="fr" {if $language == fr}selected{/if}>Fr</option>
<option value="es" {if $language == es}selected{/if}>Es</option>
<option value="it" {if $language == it}selected{/if}>It</option>
<option value="de" {if $language == de}selected{/if}>De</option>
</select>
</form>