set language in session

1 replies
ok i'm stumped. i'm not great at sessions and ran into a issue here.

i have 3 links that change the language.

index.php?lang=english
index.php?lang=french
index.php?lang=spanish

here is what i have but i know its not right.

$lang = $_GET['lang'];

if ($lang == 'spanish') {
$_SESSION['lang'] = 'spanish';
} else if ($lang == 'french') {
$_SESSION['lang'] = 'french';
} else {
$_SESSION['lang'] = 'english';
}

what i need is when someone comes to the site it defaults to english.

if they click on the french or spanish flag it will change the lang session and stay in the language they choose

there are other links int he site that do not have the ?lang= in the link so what is happening is it is defaulting back to english.

thank you for any help in advance.
#language #session #set
  • Profile picture of the author layouts4you
    please let me know if this is right or just real bad code.

    if (empty($lang)) {
    $lang = $_SESSION['lang'];
    } else {
    $lang = $_GET['lang'];
    }

    if ($lang == 'spanish') {
    $_SESSION['lang'] = 'spanish';
    } else if ($lang == 'french') {
    $_SESSION['lang'] = 'french';
    } else {
    $_SESSION['lang'] = 'english';
    }

    this fixed it but still not sure if its right.
    {{ DiscussionBoard.errors[2340698].message }}

Trending Topics