1

在我的网站上有 4 个 wordpress 安装都按语言存储在一个单独的文件夹中,现在我正在主目录中创建一个索引文件,该文件有一个表单,他们在下拉菜单中选择一种语言,所以如果他们提交我想要的语言用 php 将它“我猜在 SESSION”中存储,这样如果他们将来再次访问主目录,他们就不必再次选择语言,但他们会被重定向到 /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>
4

1 回答 1

2

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

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'];
}
于 2013-10-22T21:22:15.353 回答