language select ... need some help

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
HormonX
Forum Commoner
Posts: 50
Joined: Tue Dec 10, 2002 7:43 pm
Location: Toronto

language select ... need some help

Post by HormonX »

My task seems to be failry simple, yet I am not sure how to approach it in a simple way. What i would like to accomplish is give user a choice in language english / french.

Is there a way to declare a global variable that the page can carry on ( remember ) without having to add language selection on every link such as this http://www.somepage.com/page.php?lang=en ?

any help would be great.

thank you.

HX
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

http://us3.php.net/session

At the beginning of page.php, you could have a simple condition, stating that if $_GET['lang'] is set and has a valid value, alter the $_SESSION variable to whichever language the user is trying to view. Then when you output text, you could decide which language to output a bunch of ways - the easiest being:

Code: Select all

if ( $_SESSION['lang'] == "en" )
  echo "ENGLISH";
else if ( $_SESSION['lang'] == "fr" )
  echo "FRENCH";
else if ( $_SESSION['lang'] == "sp" )
  echo "SPANISH";
Post Reply