matthew_ellis24 Posted October 31, 2007 Share Posted October 31, 2007 I am trying to set up a php based multilanguage site. I thought about using the database for the multilingual content, but it seems more hassle than it's worth for the amount of actual writing on the site. The site is www.carabusonline.co.uk. If you select a language then all fine, but as soon as you navigate away it loses the variable and resorts to english. As always, any help greatly appreciated! Code below: the l: in the top right is my attempt at debugging and is set to: echo $lang; as defined by session.php, which is included right at the top of the page (on every page before any HTML, with no white space included): <?php SESSION_START(); if (isset($_GET['lang'])) { $lang=$_GET['lang']; $_SESSION['lang'] = $lang; } if(!isset($lang)){ $lang="en"; } ?> The language links are just: <a href="?lang=es"><img src="flags/es.jpg"></a> To call a page I use <?php $menu = "menu_".$lang.".html"; include($menu); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/ Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 change if(!isset($lang)){ $lang="en"; } to if(!isset($_SESSION['lang'])){ $lang="en"; } Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382076 Share on other sites More sharing options...
matthew_ellis24 Posted October 31, 2007 Author Share Posted October 31, 2007 Changing that gives me the following error (which just confuses me even more!): Warning: main(menu_.html): failed to open stream: No such file or directory in /export/users/mbe/pages/carabus/index.php on line 48 Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382080 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 ok try this more failsafe if(!isset($_SESSION['lang'])){ $lang="en"; } else { $lang="en"; } Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382085 Share on other sites More sharing options...
GingerRobot Posted October 31, 2007 Share Posted October 31, 2007 Try: <?php SESSION_START(); if (isset($_GET['lang'])) { $lang=$_GET['lang']; $_SESSION['lang'] = $lang; } if(!isset($_SESSION['lang'])){ $lang="en"; }else{ $lang = $_SESSION['lang']; } ?> Edit: I assume that was what was meant by the last poster. Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382087 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well the old code also would of worked fine with some modifications <?php SESSION_START(); $lang="en"; if (isset($_GET['lang'])) { $lang=$_GET['lang']; $_SESSION['lang'] = $lang; } else if (isset($_SESSION['lang'])) { $lang = $_SESSION['lang']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382090 Share on other sites More sharing options...
matthew_ellis24 Posted October 31, 2007 Author Share Posted October 31, 2007 excellent thanks. All sorted now. Always quite embarrassing when it's something so simple! Cheers Matt Quote Link to comment https://forums.phpfreaks.com/topic/75524-losing-session-variables/#findComment-382092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.