Jump to content

Help needed with language selection dropdown menu


izzy

Recommended Posts

I am trying to get my language selection to work by using a dropdown menu and saving the selection in a session variable. It will not switch the language and just stay on the default language. Even if the default language is changed and the script uploaded again the language will not change untill the browser is closed and openened again. It seems like the value in the session does not change.

Thanks in advance!!

Here is the code. It might be a mess by now because i have tried so many things.

<?
if (isset($_SESSION['lang'])){
    $lang = $_SESSION['lang'];
} else if (isset($_POST['langselect'])){
    $lang = $_POST['langselect'];
} else if (isset($_GET['langselect'])) {
    $lang = $_GET['langselect'];
}

switch ($lang) {
    case 'nederlands':
    	$_SESSION['lang'] = 'nederlands';
        include ("nl_lang.php");
        break;
    case 'enlish':
    	$_SESSION['lang'] = 'enlish';
        include ("eng_lang.php");
        break;
    default:
    	$_SESSION['lang'] = 'nederlands';
    	break;
}
langheader();
?>

<div align="right">		
	<select name="langselect">
     <option value=<?""$lang""?>>Language selection</option>
     <option value="english">Enslish</option>
     <option value="nederlands">Nederlands</option>
	</select>
</div>
Link to comment
Share on other sites

Just to be sure, you have started the session with:

session_start();

Haven't you?  I assume this is a snippet of the code...

 

Make sure you put it in a form.

<form action="" method="post">
<!-- inputs here -->
</form>

Also, you sound make sure you properly validate $lang to prevent XSS attacks.

 

Lastly, in your switch statement you have misspelt english...  In fact, you have in the select as well...

Link to comment
Share on other sites

i didn't fully understand your question, still there is for sure an error in your script, an echo is missing

<option value=<?""$lang""?>>Language selection</option>

should be

<option value="<?php echo $lang; ?>">Language selection</option>

in order to work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.