我正在尝试更改所有页面语言,但会话无效。会话在两次点击后取得以前的价值和语言变化,所以请解决这个问题。
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
if (!empty($_SESSION['lanuage'])){
if ($_SESSION['lanuage'] =='hi')
{
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
}
else if ($_SESSION['lanuage'] =='en')
{
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
}
else {}
}
else
{}
<input type="button" name="hi" id="hi" value="Hindi" onclick="get_hindi(this.id);" class="submit_sytle"/>
<input type="button" name="en" id="en" value="Eng" onclick="get_hindi(this.id);" class="submit_sytle"/>
答案 0 :(得分:0)
评论后的代码:
你可以尝试这个,它对我有用:
<?php
session_start();
if (isset($_POST['hindi_hidden'])) {
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
}
if (isset($_SESSION['lanuage']) && ($_SESSION['lanuage'] =='hi' || $_SESSION['lanuage'] =='en')) {
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
}
echo $_SESSION['lanuage'];
?>
<style>
.submit_sytle{
text-transform:capitalize;
}
</style>
<form method="post">
<input type="submit" name="hindi_hidden" id="hi" value="hindi" onclick="get_hindi(this.id);" class="submit_sytle"/>
<input type="submit" name="hindi_hidden" id="en" value="english" onclick="get_hindi(this.id);" class="submit_sytle"/>
</form>
<script>
function get_hindi(lang) {
//alert (lang);
document.getElementById('hindi_hidden').value=lang;
document.form_login.submit();
}
</script>
输出:
点击英语时 english
hindi
答案 1 :(得分:0)
Can you try this
<?php
session_start();
if(isset($_POST['hindi_hidden'])){
$_SESSION['lanuage'] = $_POST['hindi_hidden'];
} else {
$_SESSION['lanuage']='hindi';
}
echo $_SESSION['lanuage'];
?>
<style>
.submit_sytle{
text-transform:capitalize;
}
</style>
<form method="post">
<input type="submit" name="hindi_hidden" id="hi" value="hindi" onclick="get_hindi(this.id);" class="submit_sytle"/>
<input type="submit" name="hindi_hidden" id="en" value="english" onclick="get_hindi(this.id);" class="submit_sytle"/>
</form>