Jump to content

$_session language


-Ricardo

Recommended Posts

Hello,

 

I am currently making a small website that requires two languages. This is the class I made:

 

<?php

class languages {
  public function __construct() {
    if(!isset($_SESSION['language'])) {
      $_SESSION['language'] = 'nl';
    }

    $lang = isset($_GET['lang']) ? $_GET['lang'] : "";
    $languages = array('en', 'nl');

    if(in_array($lang, $languages)) {
      $_SESSION['language'] = $lang;
    }
  }
}

$languages = new languages;

$language = $_SESSION['language'];

?>

 

Now as soon I use index.php?lang=en, the website will display it self in English but, as soon I remove the &lang=en from the URI, the language gets not stored in the session and it displays nl agian.

 

Can somebody help me?

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/260473-_session-language/
Share on other sites

Your going about that in a very long winded way

 

class languages {
  public function __construct() {
    $_SESSION['language'] = (isset($_GET['lang']) && in_array($_GET['lang'], array('en', 'nl') ? $_GET['lang'] : "DEFAULT LANGUAGE");
  }
}

 

And ensure you check what the previous posts mentions...

Link to comment
https://forums.phpfreaks.com/topic/260473-_session-language/#findComment-1335083
Share on other sites

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.