Jump to content

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

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.