Session issue

Discussion in 'PHP' started by Miquexia, Nov 18, 2009.

  1. #1
    Hello there,

    I have this little annoying issue with a session.

    I'm trying to make a very simple language system.

    Here's what I got so far:

    
    <?
    
    $_SESSION['lang'] = $_GET['lang'];
    
    if ($_SESSION['lang'] == "en") {
    	include('languages/en/en.php');
    	echo 'EN';
    } else {
    	include('languages/nl/nl.php');
    	echo 'NL';
    }
    
    ?>
    
    PHP:
    This file is called languages.php and gets included in EVERY page on the site.

    Now when I add the text ?lang=en behind an URL it shows the language EN correctly. And ?lang=nl shows the language NL correctly. So the script works fine. However, when I leave that current page, the session doesn't hold the current language and switches back to the default one.

    Yes, in every page it says session_start();

    Can anyone help me out, am I missing something? :eek:

    Thanks,
    Miquexia.
     
    Miquexia, Nov 18, 2009 IP
  2. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    I think this line causing problem
    $_SESSION['lang'] = $_GET['lang'];
    PHP:
    try replacing it with
    
    if(isset($_GET['lang']) && $_GET['lang']!="") $_SESSION['lang'] = $_GET['lang'];
    
    PHP:
     
    harsh789, Nov 18, 2009 IP
  3. Miquexia

    Miquexia Peon

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perfect! Works fine ;)

    Thanks alot!!
     
    Miquexia, Nov 18, 2009 IP