Reputation: 203
i'm building a php switcher to add multilanguage capability to my site.
Every content in MySQL has a language-specific text that I want to retrieve according to the active language.
At the beginning, I thought to build a tailored table in MySQL to store the languages status.
For example:
ITALIAN 1
ENGLISH 0
..where 1 means that language is active, and 0 means is off.
Every time the user switch language, I call this table and change the language status. Then, at the end of the call, I refresh the page and php retrieve the right contents.
This seemed a good idea till I figured out that the languages status in MySQL could change every time a user switch. So, if a user is viewing the site in Italian, and other user switch to English at the same time, the first user will view the English as well.
My question is: how could I store the languages status for the specific user, avoiding change the languages status for every other user ?
Thanks a lot
Upvotes: 0
Views: 465
Reputation: 1173
If you want a persistent save, add a "Lang" column on the user table
User(id, username, passhash, lang);
And just store their language settings there. If you have another table with languages you can use a foreign key to avoid integrity issues.
If you dont care about being persistent (If the user logs from other computer it defaults back to the default language) you can use either Session or Cookies.
Upvotes: 1
Reputation: 776
Don't use the database. Set a $_SESSION
variable instead (and don't forget to call session_start()
before you modify it). (Php Manual)
Upvotes: 0