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

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.