-Ricardo Posted April 6, 2012 Share Posted April 6, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/260473-_session-language/ Share on other sites More sharing options...
onekoolman Posted April 6, 2012 Share Posted April 6, 2012 Have you started the session at this point? See session_start Quote Link to comment https://forums.phpfreaks.com/topic/260473-_session-language/#findComment-1335063 Share on other sites More sharing options...
cpd Posted April 6, 2012 Share Posted April 6, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/260473-_session-language/#findComment-1335083 Share on other sites More sharing options...
AyKay47 Posted April 6, 2012 Share Posted April 6, 2012 not sure why you are using a class either.. Quote Link to comment https://forums.phpfreaks.com/topic/260473-_session-language/#findComment-1335101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.