Forum Moderators: coopster
I have a multilanguage application.
The user can choose the display language he wants using a dropdown. I store the chosen language in the Session.
The problem:
I potentially put some objects in the Session so I have to include their class definitions BEFORE I call session_start().
In those classes, I can't do something such as "addLanguageFile($_SESSION['userLanguage'])" (that would do an "include()" of variables depending of the language chosen), because the Session is not started yet!
And I want each class file to import its own language file because I only want to include necessary variables.
See the problem?
I guess I'll have to find a new way to store the user language.
I though about cookies but maybe the user doesn't allow them.
The only solution I see is the always append the language in the URL:
www.mysite.com/en/test.php or www.mysite.com/fr/test.php
or maybe:
www.mysite.com/test.php?l=en or www.mysite.com/test.php?l=fr
Any thought?
Recommendations?
I potentially put some objects in the Session so I have to include their class definitions BEFORE I call session_start().
Why can't you start the session first, do your 'class definitions' and then deal with your session variables. Unless you are defining custom session handling code, you should be safe to start the session right at the top of your script.
Maybe I've missed the point? I do this in my own code and my session handling always comes before I call any classes.
But I think I found a solution.
The files containing the class definitions won't automatically "include()" their language file, I'll have to call a static method on them to do so, and I'll do it after the session is started.
Example:
include("aClassFileNeededBySession") ;
include("aClassFileNeededBySession2") ;
session_start();
Class1::includeLanguageFile() ;
Class2::includeLanguageFile() ;
Or something like that.
Anyway, thanks for the help!