Php 在会话中保存语言

Php 在会话中保存语言,php,wordpress,session,Php,Wordpress,Session,在我的网站上有4个wordpress安装,所有安装都按语言存储在一个单独的文件夹中,现在我正在主目录中创建一个索引文件,在该文件中,他们在下拉菜单中选择一种语言,因此如果他们提交语言,我想用php“我猜在会话中”存储它,因此,如果他们将来再次访问主目录,他们不必再次选择语言,但会被重定向到/en,/nl,。。索引页。 我对php不是很熟悉,所以有人能解释一下怎么做吗 多谢各位 <?php SESSION_START(); if (isset($_GET['en'])) { h

在我的网站上有4个wordpress安装,所有安装都按语言存储在一个单独的文件夹中,现在我正在主目录中创建一个索引文件,在该文件中,他们在下拉菜单中选择一种语言,因此如果他们提交语言,我想用php“我猜在会话中”存储它,因此,如果他们将来再次访问主目录,他们不必再次选择语言,但会被重定向到/en,/nl,。。索引页。 我对php不是很熟悉,所以有人能解释一下怎么做吗

多谢各位

<?php 
SESSION_START(); 
if (isset($_GET['en'])) { 
    header( 'Location: http://www.mysite.com/en/' ) ;
}
else if (isset($_GET['nl'])) { 
    header( 'Location: http://www.mysite.com/nl/' ) ;
}
else if (isset($_GET['de'])) { 
    header( 'Location: http://www.mysite.com/de/' ) ;
}
else if (isset($_GET['tr'])) { 
    header( 'Location: http://www.mysite.com/tr/' ) ;
}
else { 
    header( 'Location: http://www.mysite.com/' ) ;
}

?>

我尝试使用php include将其添加到页面的开头,然后将其用于表单操作,但它总是返回到索引页面

我的html:

    <form name='language' action='language.php' method='get'>
    <select>
            <option value='en'>English</option>
            <option value='nl'>Nederlands</option>
            <option value='de'>Deutsch</option>
            <option value='tr'>Turkçe</option>
    </select>
    <input type='submit' value='Submit'><br/>
</form>

英语
荷兰语
德国
特克斯


当用户访问从中选择语言的页面时,您会检查他们是否已经选择了类似以下内容的语言:

if(isset($_SESSION['preferred_language'])){
    //forward the user here using php's header function
    //see this link for more info: http://php.net/manual/en/function.header.php
}
else{ //If the user has not yet selected a language
    //display the page so the user can select a language, then set that language like this:
    $_SESSION['preferred_language'] = $_GET['preferred_language'];
}