PHP multi-Language Help needed guys.... :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ceylongeek
Forum Newbie
Posts: 3
Joined: Mon Jul 26, 2010 7:24 pm

PHP multi-Language Help needed guys.... :(

Post by ceylongeek »

Guys i am new to PHP and have created a simple multi-language website.It is using a very basic logic to change the languages.

It works based on $_GET so to hold the language as it is i have to protect the URL as "www.blablabla.com/index.php?lang=en" for English or "www.blablabla.com/index.php?lang=jp" for Japanees.But guys when i put a link inside the main page to a sub page the URL get change like "www.blablabla.com/sub.php".After that website doesn't work because URL does not provide a value to that $_Get function

This is the language switching logic.

Code: Select all

if(isset($_GET['lang']))
  {
      $lang=$_GET['lang'];
  }
  
  else
  
  {
      $lang='en';
  }
  
  switch ($lang)
  {
      case  'en';
      $lang_file = 'en.php';
      break;
      
      case 'jp';
      $lang_file = 'jp.php';
      break;
      
      default;
      $lang_file = 'en.php';
  }
To hold a one language all around my website, selected by the visitor what should i do?.How to protect that lang=en in the URL every time in a new Link?.


Please give me a idea to solve my problem. :)
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: PHP multi-Language Help needed guys.... :(

Post by iijb »

Hi,
Use a Session variable to store the visitor's language choice. Then check with it.

Regards
iijb
ceylongeek
Forum Newbie
Posts: 3
Joined: Mon Jul 26, 2010 7:24 pm

Re: PHP multi-Language Help needed guys.... :(

Post by ceylongeek »

iijb wrote:Hi,
Use a Session variable to store the visitor's language choice. Then check with it.

Regards
iijb

Your mechanism worked perfectly....... :D
Thank you very much iijb i successfully did that.
Post Reply