Jump to content

A language switcher between English and French


janggu

Recommended Posts

Hi there,

 

I need to create a language swticher script between English and French content. I am kind of stuck how I can approach this. Is using PHP cookie the best way - I need to triger the switcher by clicking English/French link? Has anyone done this type of work?

 

Thanks a lot for your help in advance!

Link to comment
Share on other sites

This is what have so far. Basically, I have two links of English/French with a query string called "lang". When one of these links is clicked, my script is supposed to create or update the session variables. Howerver, this is not working... PLEASE HELP!!!

 

<?

session_start();

$lg = $_GET['lang'];

 

if (!isset($_SESSION["lang"]))

{

$_SESSION['lang'] = "en";

}

else

{

if ($_SESSION["lang"] == "en" && $lg == "fr")

{

session_destroy();

$_SESSION["lang"] = "fr";

}

if ($_SESSION["lang"] == "fr" && $lg == "en")

{

session_destroy();

$_SESSION["lang"] = "en";

}

}

?>

 

Link to comment
Share on other sites

<?php
session_start();
$langs = array("ENG","FRA"):
if(in_array($_GET['lang'],$langs)){
   $_SESSION['Lang'] = $_GET['lang'];
}
if(in_array($_SESSION['Lang'],$langs)){
    $_SESSION['Lang'] = $langs[0];
}
?>

 

 

That will do it it will verify a get version is legit if the session isn't set or is invalid it resets it to the default first value.  You can add more languages very easily with this.

 

Make sure all this appears pre any headers being sent so the page is reflective of the new header data.

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.