tags:

views:

53

answers:

5

Hello , I'm making a multi language website and i decided to use sessions to remember the current language , overall it works as its supposed to , but there is one bug that i can't fix . 1) i load the page and it displays properly in Bulgaria 2) i add '&lang=en' to test if its working properly , and it does 3) when i remove the '&lang=en' and its back to Bulgarian when its not supposed to its supposed to stay in English

here is what is in the header of the page

   if(isset($_GET['lang'])){
    $lang = htmlspecialchars($_GET['lang']);
lang($lang);
}
if(!isset($_SESSION['slang'])){
    lang('bg');
}else {
    lang($_SESSION['slang']);
}

and here is my function that handles the language switching

function lang($lang=''){

     if($lang=='bg'){
      $_SESSION['slang'] = 'bg' ;
      include_once('./includes/bulgarian.php');
     }
     if ($lang == 'en'){
      $_SESSION['slang'] = 'en' ;
      include_once('./includes/english.php');
     }else {
      $_SESSION['slang'] = 'bg' ;
      include_once('./includes/bulgarian.php');
     }

}

if someone can explain me why this is happening and how i can fix it it would be great Thanks

A: 

Browser cache? Can you clear all saved info in the browser and then try?

Devin Ceartas
+2  A: 

Judging from what you wrote the code should work you should check if $_SESSION actually gets across pages.

Are you using: session_start(); ?

0plus1
+4  A: 

Make sure you're calling session_start on each page. I tried it on my computer, and got your results without the session_start. When I added it, it worked as desired.

You can try using echo session_id(); to see if the session is started on any page

davethegr8
yup , i forgot that i must start a session >_> excuse me
Aviatrix
no worries. glad that fixed it!
davethegr8
A: 

Please call session_start() to load your session.

devpl
+1  A: 

I would just use the Gnu's gettext spec if I were you: http://en.wikipedia.org/wiki/Gettext

Zack
i might use that in future projects ! thanks for pointing it out !
Aviatrix