【问题标题】:save language in session在会话中保存语言
【发布时间】:2013-10-22 21:09:44
【问题描述】:

在我的网站上有 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>

【问题讨论】:

    标签: php wordpress session


    【解决方案1】:

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

    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'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多