Page 1 of 1

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

Posted: Mon Jul 26, 2010 7:51 pm
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. :)

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

Posted: Tue Jul 27, 2010 12:14 am
by iijb
Hi,
Use a Session variable to store the visitor's language choice. Then check with it.

Regards
iijb

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

Posted: Tue Jul 27, 2010 8:22 pm
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.