izzy Posted March 17, 2015 Share Posted March 17, 2015 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> Quote Link to comment Share on other sites More sharing options...
kierany5 Posted March 17, 2015 Share Posted March 17, 2015 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... Quote Link to comment Share on other sites More sharing options...
cypher86 Posted March 17, 2015 Share Posted March 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.