Jump to content

[SOLVED] Problem with keeping a $_SESSION variable (Language)


gasma1975

Recommended Posts

Hi,

 

I'm designing a multi language Website french/english. I have a dropdown with a button that will SET a global variable. Value 1 = English and 2 = French, the default language is value 1 (english)

 

But when the person switch the language I will also Set the corresponding value in the dropdown and I will translate the website content. On my index.php page everything is fine. But if the person has selected the french language, when he's redirected to another page, the page is in english not french. I have to select the drop down language on each page ! very annoying.

 

How can make it constant ?

 

This is the code that will handle the drop down selection lnaguage

 

if(isset($_POST['ChangeLanguage']))

{

  unset($_SESSION['lang']);

  $lang= $_POST['lang'];

 

  if ($lang == 1)

  {

    //English picked, load English page

    $_SESSION['lang']=1;

  }

  elseif ($lang == 2)

  {

    //French picked, load French page

    $_SESSION['lang']=2;

  }

}

 

 

This is the button and dropdown

 

<form method="post" class="searchform" action="#">

          <div align="right">

              <select name="lang">

                <option value= "1" <?php if($_SESSION['lang']==1){echo 'selected="selected"';} ?>> English</option>

                <option value= "2" <?php if($_SESSION['lang']==2){echo 'selected="selected"';} ?> >Francais</option>

              </select>

              <input type="submit" name="ChangeLanguage" value="Go" />

            </div>

  </form>

 

thank you,

 

gasma1975

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.