save language in session

have 4 wordpress installations on my site all stored in a separate folder by language, now I am making a index file in the main directory that has a form where they select a language in a dropdown menu, so if they submit the language I want to store it ‘I guess in SESSION’ with php, so that if they visit the main directory again in the future they don’t have to select the language again but they get redirected to the /en, /nl,.. index page.
I’m not very familiar with php so can anyone explain how to do this please?

thank you

Read More
<?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/' ) ;
}

?>

i tried adding this to the beginning of the page with php include and then also using it for the form action but it always returns to the index page

My 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>

Related posts

Leave a Reply

1 comment

  1. When the user visits the page from which the language is selected, you check if they’ve already selected a language with something like this:

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